blob: 5105084c0a2e99492e344c46684fac385b0aaa98 [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 Lindgren9d8813612021-09-21 12:42:25 +03009#include <linux/cpu_pm.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080010#include <linux/delay.h>
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080011#include <linux/list.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070012#include <linux/module.h>
13#include <linux/platform_device.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080014#include <linux/pm_domain.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070015#include <linux/pm_runtime.h>
Tony Lindgren50622362018-04-16 10:20:27 -070016#include <linux/reset.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070017#include <linux/of_address.h>
18#include <linux/of_platform.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080019#include <linux/slab.h>
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080020#include <linux/sys_soc.h>
Tony Lindgrenb3e94312021-09-21 12:42:25 +030021#include <linux/timekeeping.h>
Faiz Abbas596e7952018-07-09 22:18:39 +053022#include <linux/iopoll.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080023
Tony Lindgren70a65242017-12-15 09:41:09 -080024#include <linux/platform_data/ti-sysc.h>
25
26#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070027
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080028#define DIS_ISP BIT(2)
29#define DIS_IVA BIT(1)
30#define DIS_SGX BIT(0)
31
32#define SOC_FLAG(match, flag) { .machine = match, .data = (void *)(flag), }
33
Tony Lindgrene4a8fc02020-06-10 15:31:54 -070034#define MAX_MODULE_SOFTRESET_WAIT 10000
Faiz Abbas596e7952018-07-09 22:18:39 +053035
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080036enum sysc_soc {
37 SOC_UNKNOWN,
38 SOC_2420,
39 SOC_2430,
40 SOC_3430,
41 SOC_3630,
42 SOC_4430,
43 SOC_4460,
44 SOC_4470,
45 SOC_5430,
46 SOC_AM3,
47 SOC_AM4,
48 SOC_DRA7,
49};
50
51struct sysc_address {
52 unsigned long base;
53 struct list_head node;
54};
55
Tony Lindgren9d8813612021-09-21 12:42:25 +030056struct sysc_module {
57 struct sysc *ddata;
58 struct list_head node;
59};
60
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080061struct sysc_soc_info {
62 unsigned long general_purpose:1;
63 enum sysc_soc soc;
Tony Lindgren9d8813612021-09-21 12:42:25 +030064 struct mutex list_lock; /* disabled and restored modules list lock */
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080065 struct list_head disabled_modules;
Tony Lindgren9d8813612021-09-21 12:42:25 +030066 struct list_head restored_modules;
67 struct notifier_block nb;
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080068};
Tony Lindgren0eecc632017-10-10 14:23:43 -070069
70enum sysc_clocks {
71 SYSC_FCK,
72 SYSC_ICK,
Tony Lindgren09dfe582018-04-16 10:25:52 -070073 SYSC_OPTFCK0,
74 SYSC_OPTFCK1,
75 SYSC_OPTFCK2,
76 SYSC_OPTFCK3,
77 SYSC_OPTFCK4,
78 SYSC_OPTFCK5,
79 SYSC_OPTFCK6,
80 SYSC_OPTFCK7,
Tony Lindgren0eecc632017-10-10 14:23:43 -070081 SYSC_MAX_CLOCKS,
82};
83
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080084static struct sysc_soc_info *sysc_soc;
85static const char * const reg_names[] = { "rev", "sysc", "syss", };
Tony Lindgrena54275f2019-03-21 11:00:21 -070086static const char * const clock_names[SYSC_MAX_CLOCKS] = {
87 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
88 "opt5", "opt6", "opt7",
89};
Tony Lindgren0eecc632017-10-10 14:23:43 -070090
Tony Lindgrenc5a2de92017-12-15 09:41:23 -080091#define SYSC_IDLEMODE_MASK 3
92#define SYSC_CLOCKACTIVITY_MASK 3
93
Tony Lindgren0eecc632017-10-10 14:23:43 -070094/**
95 * struct sysc - TI sysc interconnect target module registers and capabilities
96 * @dev: struct device pointer
97 * @module_pa: physical address of the interconnect target module
98 * @module_size: size of the interconnect target module
99 * @module_va: virtual address of the interconnect target module
100 * @offsets: register offsets from module base
Suman Annab58056d2019-08-13 04:13:32 -0700101 * @mdata: ti-sysc to hwmod translation data for a module
Tony Lindgren0eecc632017-10-10 14:23:43 -0700102 * @clocks: clocks used by the interconnect target module
Tony Lindgren09dfe582018-04-16 10:25:52 -0700103 * @clock_roles: clock role names for the found clocks
104 * @nr_clocks: number of clocks used by the interconnect target module
Suman Annab58056d2019-08-13 04:13:32 -0700105 * @rsts: resets used by the interconnect target module
Tony Lindgren0eecc632017-10-10 14:23:43 -0700106 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -0800107 * @cap: interconnect target module capabilities
108 * @cfg: interconnect target module configuration
Suman Annab58056d2019-08-13 04:13:32 -0700109 * @cookie: data used by legacy platform callbacks
Tony Lindgren566a9b052017-12-15 09:41:19 -0800110 * @name: name if available
111 * @revision: interconnect target module revision
Tony Lindgren3ff340e2021-06-11 08:42:50 +0300112 * @reserved: target module is reserved and already in use
Suman Annab58056d2019-08-13 04:13:32 -0700113 * @enabled: sysc runtime enabled status
Tony Lindgren62020f22018-02-22 13:59:44 -0800114 * @needs_resume: runtime resume needed on resume from suspend
Suman Annab58056d2019-08-13 04:13:32 -0700115 * @child_needs_resume: runtime resume needed for child on resume from suspend
116 * @disable_on_idle: status flag used for disabling modules with resets
117 * @idle_work: work structure used to perform delayed idle on a module
Tony Lindgrene64c0212020-02-24 12:58:03 -0800118 * @pre_reset_quirk: module specific pre-reset quirk
119 * @post_reset_quirk: module specific post-reset quirk
Tony Lindgren4e23be42019-06-10 04:48:05 -0700120 * @reset_done_quirk: module specific reset done quirk
Tony Lindgrend7f563d2019-08-14 05:18:16 -0700121 * @module_enable_quirk: module specific enable quirk
Tony Lindgrenc7d86692019-10-17 11:21:44 -0700122 * @module_disable_quirk: module specific disable quirk
Tony Lindgrene8639e12020-02-24 12:58:03 -0800123 * @module_unlock_quirk: module specific sysconfig unlock quirk
124 * @module_lock_quirk: module specific sysconfig lock quirk
Tony Lindgren0eecc632017-10-10 14:23:43 -0700125 */
126struct sysc {
127 struct device *dev;
128 u64 module_pa;
129 u32 module_size;
130 void __iomem *module_va;
131 int offsets[SYSC_MAX_REGS];
Tony Lindgrena3e92e72019-03-21 11:00:21 -0700132 struct ti_sysc_module_data *mdata;
Tony Lindgren09dfe582018-04-16 10:25:52 -0700133 struct clk **clocks;
134 const char **clock_roles;
135 int nr_clocks;
Tony Lindgren50622362018-04-16 10:20:27 -0700136 struct reset_control *rsts;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700137 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -0800138 const struct sysc_capabilities *cap;
139 struct sysc_config cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800140 struct ti_sysc_cookie cookie;
Tony Lindgren566a9b052017-12-15 09:41:19 -0800141 const char *name;
142 u32 revision;
Tony Lindgren95ec14fa2021-09-21 12:42:25 +0300143 u32 sysconfig;
Tony Lindgren3ff340e2021-06-11 08:42:50 +0300144 unsigned int reserved:1;
Tony Lindgren8383e252019-05-27 04:51:56 -0700145 unsigned int enabled:1;
146 unsigned int needs_resume:1;
147 unsigned int child_needs_resume:1;
Tony Lindgren76f0f772018-02-23 08:28:45 -0800148 struct delayed_work idle_work;
Tony Lindgrene64c0212020-02-24 12:58:03 -0800149 void (*pre_reset_quirk)(struct sysc *sysc);
150 void (*post_reset_quirk)(struct sysc *sysc);
Tony Lindgren4e23be42019-06-10 04:48:05 -0700151 void (*reset_done_quirk)(struct sysc *sysc);
Tony Lindgrend7f563d2019-08-14 05:18:16 -0700152 void (*module_enable_quirk)(struct sysc *sysc);
Tony Lindgrenc7d86692019-10-17 11:21:44 -0700153 void (*module_disable_quirk)(struct sysc *sysc);
Tony Lindgrene8639e12020-02-24 12:58:03 -0800154 void (*module_unlock_quirk)(struct sysc *sysc);
155 void (*module_lock_quirk)(struct sysc *sysc);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700156};
157
Tony Lindgren4014c082018-12-10 14:11:26 -0800158static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
159 bool is_child);
Tony Lindgren6a52bc22021-09-21 12:42:25 +0300160static int sysc_reset(struct sysc *ddata);
Tony Lindgren4014c082018-12-10 14:11:26 -0800161
Tony Lindgrenb7182b42019-03-21 11:00:21 -0700162static void sysc_write(struct sysc *ddata, int offset, u32 value)
Faiz Abbas596e7952018-07-09 22:18:39 +0530163{
Tony Lindgren5aa91292019-05-27 04:51:53 -0700164 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
165 writew_relaxed(value & 0xffff, ddata->module_va + offset);
166
167 /* Only i2c revision has LO and HI register with stride of 4 */
168 if (ddata->offsets[SYSC_REVISION] >= 0 &&
169 offset == ddata->offsets[SYSC_REVISION]) {
170 u16 hi = value >> 16;
171
172 writew_relaxed(hi, ddata->module_va + offset + 4);
173 }
174
175 return;
176 }
177
Faiz Abbas596e7952018-07-09 22:18:39 +0530178 writel_relaxed(value, ddata->module_va + offset);
179}
180
Tony Lindgren566a9b052017-12-15 09:41:19 -0800181static u32 sysc_read(struct sysc *ddata, int offset)
182{
183 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
184 u32 val;
185
186 val = readw_relaxed(ddata->module_va + offset);
Tony Lindgren5aa91292019-05-27 04:51:53 -0700187
188 /* Only i2c revision has LO and HI register with stride of 4 */
189 if (ddata->offsets[SYSC_REVISION] >= 0 &&
190 offset == ddata->offsets[SYSC_REVISION]) {
191 u16 tmp = readw_relaxed(ddata->module_va + offset + 4);
192
193 val |= tmp << 16;
194 }
Tony Lindgren566a9b052017-12-15 09:41:19 -0800195
196 return val;
197 }
198
199 return readl_relaxed(ddata->module_va + offset);
200}
201
Tony Lindgren09dfe582018-04-16 10:25:52 -0700202static bool sysc_opt_clks_needed(struct sysc *ddata)
203{
204 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
205}
206
Tony Lindgren0eecc632017-10-10 14:23:43 -0700207static u32 sysc_read_revision(struct sysc *ddata)
208{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800209 int offset = ddata->offsets[SYSC_REVISION];
210
211 if (offset < 0)
212 return 0;
213
214 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700215}
216
Tony Lindgrene0db94f2019-05-27 04:51:53 -0700217static u32 sysc_read_sysconfig(struct sysc *ddata)
218{
219 int offset = ddata->offsets[SYSC_SYSCONFIG];
220
221 if (offset < 0)
222 return 0;
223
224 return sysc_read(ddata, offset);
225}
226
227static u32 sysc_read_sysstatus(struct sysc *ddata)
228{
229 int offset = ddata->offsets[SYSC_SYSSTATUS];
230
231 if (offset < 0)
232 return 0;
233
234 return sysc_read(ddata, offset);
235}
236
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300237static int sysc_poll_reset_sysstatus(struct sysc *ddata)
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700238{
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300239 int error, retries;
240 u32 syss_done, rstval;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700241
242 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
243 syss_done = 0;
244 else
245 syss_done = ddata->cfg.syss_mask;
246
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300247 if (likely(!timekeeping_suspended)) {
Tony Lindgren9f911392020-07-02 10:44:20 -0700248 error = readx_poll_timeout_atomic(sysc_read_sysstatus, ddata,
249 rstval, (rstval & ddata->cfg.syss_mask) ==
250 syss_done, 100, MAX_MODULE_SOFTRESET_WAIT);
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300251 } else {
252 retries = MAX_MODULE_SOFTRESET_WAIT;
253 while (retries--) {
254 rstval = sysc_read_sysstatus(ddata);
255 if ((rstval & ddata->cfg.syss_mask) == syss_done)
256 return 0;
257 udelay(2); /* Account for udelay flakeyness */
258 }
259 error = -ETIMEDOUT;
260 }
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700261
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300262 return error;
263}
264
265static int sysc_poll_reset_sysconfig(struct sysc *ddata)
266{
267 int error, retries;
268 u32 sysc_mask, rstval;
269
270 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
271
272 if (likely(!timekeeping_suspended)) {
Tony Lindgren9f911392020-07-02 10:44:20 -0700273 error = readx_poll_timeout_atomic(sysc_read_sysconfig, ddata,
274 rstval, !(rstval & sysc_mask),
275 100, MAX_MODULE_SOFTRESET_WAIT);
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300276 } else {
277 retries = MAX_MODULE_SOFTRESET_WAIT;
278 while (retries--) {
279 rstval = sysc_read_sysconfig(ddata);
280 if (!(rstval & sysc_mask))
281 return 0;
282 udelay(2); /* Account for udelay flakeyness */
283 }
284 error = -ETIMEDOUT;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700285 }
286
287 return error;
288}
289
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300290/* Poll on reset status */
291static int sysc_wait_softreset(struct sysc *ddata)
292{
293 int syss_offset, error = 0;
294
295 if (ddata->cap->regbits->srst_shift < 0)
296 return 0;
297
298 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
299
300 if (syss_offset >= 0)
301 error = sysc_poll_reset_sysstatus(ddata);
302 else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS)
303 error = sysc_poll_reset_sysconfig(ddata);
304
305 return error;
306}
307
Tony Lindgrena54275f2019-03-21 11:00:21 -0700308static int sysc_add_named_clock_from_child(struct sysc *ddata,
309 const char *name,
310 const char *optfck_name)
311{
312 struct device_node *np = ddata->dev->of_node;
313 struct device_node *child;
314 struct clk_lookup *cl;
315 struct clk *clock;
316 const char *n;
317
318 if (name)
319 n = name;
320 else
321 n = optfck_name;
322
323 /* Does the clock alias already exist? */
324 clock = of_clk_get_by_name(np, n);
325 if (!IS_ERR(clock)) {
326 clk_put(clock);
327
328 return 0;
329 }
330
331 child = of_get_next_available_child(np, NULL);
332 if (!child)
333 return -ENODEV;
334
335 clock = devm_get_clk_from_child(ddata->dev, child, name);
336 if (IS_ERR(clock))
337 return PTR_ERR(clock);
338
339 /*
340 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
341 * limit for clk_get(). If cl ever needs to be freed, it should be done
342 * with clkdev_drop().
343 */
Zheng Yongjund995d3d2020-12-29 21:51:47 +0800344 cl = kzalloc(sizeof(*cl), GFP_KERNEL);
Tony Lindgrena54275f2019-03-21 11:00:21 -0700345 if (!cl)
346 return -ENOMEM;
347
348 cl->con_id = n;
349 cl->dev_id = dev_name(ddata->dev);
350 cl->clk = clock;
351 clkdev_add(cl);
352
353 clk_put(clock);
354
355 return 0;
356}
357
358static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
359{
360 const char *optfck_name;
361 int error, index;
362
363 if (ddata->nr_clocks < SYSC_OPTFCK0)
364 index = SYSC_OPTFCK0;
365 else
366 index = ddata->nr_clocks;
367
368 if (name)
369 optfck_name = name;
370 else
371 optfck_name = clock_names[index];
372
373 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
374 if (error)
375 return error;
376
377 ddata->clock_roles[index] = optfck_name;
378 ddata->nr_clocks++;
379
380 return 0;
381}
382
Tony Lindgren09dfe582018-04-16 10:25:52 -0700383static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700384{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700385 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700386
Tony Lindgren09dfe582018-04-16 10:25:52 -0700387 if (!strncmp(clock_names[SYSC_FCK], name, 3))
388 index = SYSC_FCK;
389 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
390 index = SYSC_ICK;
391
392 if (index < 0) {
393 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700394 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700395 index = i;
396 break;
397 }
398 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700399 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700400
401 if (index < 0) {
402 dev_err(ddata->dev, "clock %s not added\n", name);
403 return index;
404 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700405
406 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
407 if (IS_ERR(ddata->clocks[index])) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700408 dev_err(ddata->dev, "clock get error for %s: %li\n",
409 name, PTR_ERR(ddata->clocks[index]));
410
411 return PTR_ERR(ddata->clocks[index]);
412 }
413
414 error = clk_prepare(ddata->clocks[index]);
415 if (error) {
416 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
417 name, error);
418
419 return error;
420 }
421
422 return 0;
423}
424
425static int sysc_get_clocks(struct sysc *ddata)
426{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700427 struct device_node *np = ddata->dev->of_node;
428 struct property *prop;
429 const char *name;
430 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700431
Kees Cook20749052018-06-18 10:45:49 -0700432 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700433 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700434 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700435 GFP_KERNEL);
436 if (!ddata->clock_roles)
437 return -ENOMEM;
438
439 of_property_for_each_string(np, "clock-names", prop, name) {
440 if (!strncmp(clock_names[SYSC_FCK], name, 3))
441 nr_fck++;
442 if (!strncmp(clock_names[SYSC_ICK], name, 3))
443 nr_ick++;
444 ddata->clock_roles[ddata->nr_clocks] = name;
445 ddata->nr_clocks++;
446 }
447
448 if (ddata->nr_clocks < 1)
449 return 0;
450
Tony Lindgrena54275f2019-03-21 11:00:21 -0700451 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
452 error = sysc_init_ext_opt_clock(ddata, NULL);
453 if (error)
454 return error;
455 }
456
Tony Lindgren09dfe582018-04-16 10:25:52 -0700457 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
458 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
459
460 return -EINVAL;
461 }
462
463 if (nr_fck > 1 || nr_ick > 1) {
464 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
465
466 return -EINVAL;
467 }
468
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800469 /* Always add a slot for main clocks fck and ick even if unused */
470 if (!nr_fck)
471 ddata->nr_clocks++;
472 if (!nr_ick)
473 ddata->nr_clocks++;
474
Kees Cook20749052018-06-18 10:45:49 -0700475 ddata->clocks = devm_kcalloc(ddata->dev,
476 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700477 GFP_KERNEL);
478 if (!ddata->clocks)
479 return -ENOMEM;
480
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800481 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
482 const char *name = ddata->clock_roles[i];
483
484 if (!name)
485 continue;
486
487 error = sysc_get_one_clock(ddata, name);
Tony Lindgren2783d062019-09-05 13:01:29 -0700488 if (error)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700489 return error;
490 }
491
492 return 0;
493}
494
Tony Lindgrend8789702019-03-21 11:00:21 -0700495static int sysc_enable_main_clocks(struct sysc *ddata)
496{
497 struct clk *clock;
498 int i, error;
499
500 if (!ddata->clocks)
501 return 0;
502
503 for (i = 0; i < SYSC_OPTFCK0; i++) {
504 clock = ddata->clocks[i];
505
506 /* Main clocks may not have ick */
507 if (IS_ERR_OR_NULL(clock))
508 continue;
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
521 /* Main clocks may not have ick */
522 if (IS_ERR_OR_NULL(clock))
523 continue;
524
525 clk_disable(clock);
526 }
527
528 return error;
529}
530
531static void sysc_disable_main_clocks(struct sysc *ddata)
532{
533 struct clk *clock;
534 int i;
535
536 if (!ddata->clocks)
537 return;
538
539 for (i = 0; i < SYSC_OPTFCK0; i++) {
540 clock = ddata->clocks[i];
541 if (IS_ERR_OR_NULL(clock))
542 continue;
543
544 clk_disable(clock);
545 }
546}
547
548static int sysc_enable_opt_clocks(struct sysc *ddata)
549{
550 struct clk *clock;
551 int i, error;
552
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800553 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700554 return 0;
555
556 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
557 clock = ddata->clocks[i];
558
559 /* Assume no holes for opt clocks */
560 if (IS_ERR_OR_NULL(clock))
561 return 0;
562
563 error = clk_enable(clock);
564 if (error)
565 goto err_disable;
566 }
567
568 return 0;
569
570err_disable:
571 for (i--; i >= 0; i--) {
572 clock = ddata->clocks[i];
573 if (IS_ERR_OR_NULL(clock))
574 continue;
575
576 clk_disable(clock);
577 }
578
579 return error;
580}
581
582static void sysc_disable_opt_clocks(struct sysc *ddata)
583{
584 struct clk *clock;
585 int i;
586
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800587 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700588 return;
589
590 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
591 clock = ddata->clocks[i];
592
593 /* Assume no holes for opt clocks */
594 if (IS_ERR_OR_NULL(clock))
595 return;
596
597 clk_disable(clock);
598 }
599}
600
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700601static void sysc_clkdm_deny_idle(struct sysc *ddata)
602{
603 struct ti_sysc_platform_data *pdata;
604
Tony Lindgren94f63452019-12-12 08:57:58 -0800605 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700606 return;
607
608 pdata = dev_get_platdata(ddata->dev);
609 if (pdata && pdata->clkdm_deny_idle)
610 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
611}
612
613static void sysc_clkdm_allow_idle(struct sysc *ddata)
614{
615 struct ti_sysc_platform_data *pdata;
616
Tony Lindgren94f63452019-12-12 08:57:58 -0800617 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700618 return;
619
620 pdata = dev_get_platdata(ddata->dev);
621 if (pdata && pdata->clkdm_allow_idle)
622 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
623}
624
Tony Lindgren0eecc632017-10-10 14:23:43 -0700625/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700626 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700627 * @ddata: device driver data
628 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700629 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700630 */
631static int sysc_init_resets(struct sysc *ddata)
632{
Tony Lindgren50622362018-04-16 10:20:27 -0700633 ddata->rsts =
Tero Kristobb88b862019-08-07 15:46:05 +0300634 devm_reset_control_get_optional_shared(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700635
zhengbin3f2c4202019-11-18 18:37:32 +0800636 return PTR_ERR_OR_ZERO(ddata->rsts);
Tony Lindgren50622362018-04-16 10:20:27 -0700637}
638
639/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700640 * sysc_parse_and_check_child_range - parses module IO region from ranges
641 * @ddata: device driver data
642 *
643 * In general we only need rev, syss, and sysc registers and not the whole
644 * module range. But we do want the offsets for these registers from the
645 * module base. This allows us to check them against the legacy hwmod
646 * platform data. Let's also check the ranges are configured properly.
647 */
648static int sysc_parse_and_check_child_range(struct sysc *ddata)
649{
650 struct device_node *np = ddata->dev->of_node;
651 const __be32 *ranges;
652 u32 nr_addr, nr_size;
653 int len, error;
654
655 ranges = of_get_property(np, "ranges", &len);
656 if (!ranges) {
657 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
658
659 return -ENOENT;
660 }
661
662 len /= sizeof(*ranges);
663
664 if (len < 3) {
665 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
666
667 return -EINVAL;
668 }
669
670 error = of_property_read_u32(np, "#address-cells", &nr_addr);
671 if (error)
672 return -ENOENT;
673
674 error = of_property_read_u32(np, "#size-cells", &nr_size);
675 if (error)
676 return -ENOENT;
677
678 if (nr_addr != 1 || nr_size != 1) {
679 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
680
681 return -EINVAL;
682 }
683
684 ranges++;
685 ddata->module_pa = of_translate_address(np, ranges++);
686 ddata->module_size = be32_to_cpup(ranges);
687
Tony Lindgren0eecc632017-10-10 14:23:43 -0700688 return 0;
689}
690
Tony Lindgren4700a002021-03-08 11:35:07 +0200691/* Interconnect instances to probe before l4_per instances */
692static struct resource early_bus_ranges[] = {
693 /* am3/4 l4_wkup */
694 { .start = 0x44c00000, .end = 0x44c00000 + 0x300000, },
695 /* omap4/5 and dra7 l4_cfg */
696 { .start = 0x4a000000, .end = 0x4a000000 + 0x300000, },
697 /* omap4 l4_wkup */
698 { .start = 0x4a300000, .end = 0x4a300000 + 0x30000, },
699 /* omap5 and dra7 l4_wkup without dra7 dcan segment */
700 { .start = 0x4ae00000, .end = 0x4ae00000 + 0x30000, },
701};
702
703static atomic_t sysc_defer = ATOMIC_INIT(10);
704
705/**
706 * sysc_defer_non_critical - defer non_critical interconnect probing
707 * @ddata: device driver data
708 *
709 * We want to probe l4_cfg and l4_wkup interconnect instances before any
710 * l4_per instances as l4_per instances depend on resources on l4_cfg and
711 * l4_wkup interconnects.
712 */
713static int sysc_defer_non_critical(struct sysc *ddata)
714{
715 struct resource *res;
716 int i;
717
718 if (!atomic_read(&sysc_defer))
719 return 0;
720
721 for (i = 0; i < ARRAY_SIZE(early_bus_ranges); i++) {
722 res = &early_bus_ranges[i];
723 if (ddata->module_pa >= res->start &&
724 ddata->module_pa <= res->end) {
725 atomic_set(&sysc_defer, 0);
726
727 return 0;
728 }
729 }
730
731 atomic_dec_if_positive(&sysc_defer);
732
733 return -EPROBE_DEFER;
734}
735
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800736static struct device_node *stdout_path;
737
738static void sysc_init_stdout_path(struct sysc *ddata)
739{
740 struct device_node *np = NULL;
741 const char *uart;
742
743 if (IS_ERR(stdout_path))
744 return;
745
746 if (stdout_path)
747 return;
748
749 np = of_find_node_by_path("/chosen");
750 if (!np)
751 goto err;
752
753 uart = of_get_property(np, "stdout-path", NULL);
754 if (!uart)
755 goto err;
756
757 np = of_find_node_by_path(uart);
758 if (!np)
759 goto err;
760
761 stdout_path = np;
762
763 return;
764
765err:
766 stdout_path = ERR_PTR(-ENODEV);
767}
768
769static void sysc_check_quirk_stdout(struct sysc *ddata,
770 struct device_node *np)
771{
772 sysc_init_stdout_path(ddata);
773 if (np != stdout_path)
774 return;
775
776 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
777 SYSC_QUIRK_NO_RESET_ON_INIT;
778}
779
Tony Lindgren0eecc632017-10-10 14:23:43 -0700780/**
781 * sysc_check_one_child - check child configuration
782 * @ddata: device driver data
783 * @np: child device node
784 *
785 * Let's avoid messy situations where we have new interconnect target
786 * node but children have "ti,hwmods". These belong to the interconnect
787 * target node and are managed by this driver.
788 */
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530789static void sysc_check_one_child(struct sysc *ddata,
790 struct device_node *np)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700791{
792 const char *name;
793
794 name = of_get_property(np, "ti,hwmods", NULL);
Tony Lindgren7320fd32020-02-24 12:58:03 -0800795 if (name && !of_device_is_compatible(np, "ti,sysc"))
Tony Lindgren0eecc632017-10-10 14:23:43 -0700796 dev_warn(ddata->dev, "really a child ti,hwmods property?");
797
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800798 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800799 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700800}
801
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530802static void sysc_check_children(struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700803{
804 struct device_node *child;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700805
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530806 for_each_child_of_node(ddata->dev->of_node, child)
807 sysc_check_one_child(ddata, child);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700808}
809
Tony Lindgrena7199e22017-12-15 09:41:14 -0800810/*
811 * So far only I2C uses 16-bit read access with clockactivity with revision
812 * in two registers with stride of 4. We can detect this based on the rev
813 * register size to configure things far enough to be able to properly read
814 * the revision register.
815 */
816static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
817{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800818 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800819 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800820}
821
Tony Lindgren0eecc632017-10-10 14:23:43 -0700822/**
823 * sysc_parse_one - parses the interconnect target module registers
824 * @ddata: device driver data
825 * @reg: register to parse
826 */
827static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
828{
829 struct resource *res;
830 const char *name;
831
832 switch (reg) {
833 case SYSC_REVISION:
834 case SYSC_SYSCONFIG:
835 case SYSC_SYSSTATUS:
836 name = reg_names[reg];
837 break;
838 default:
839 return -EINVAL;
840 }
841
842 res = platform_get_resource_byname(to_platform_device(ddata->dev),
843 IORESOURCE_MEM, name);
844 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700845 ddata->offsets[reg] = -ENODEV;
846
847 return 0;
848 }
849
850 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800851 if (reg == SYSC_REVISION)
852 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700853
854 return 0;
855}
856
857static int sysc_parse_registers(struct sysc *ddata)
858{
859 int i, error;
860
861 for (i = 0; i < SYSC_MAX_REGS; i++) {
862 error = sysc_parse_one(ddata, i);
863 if (error)
864 return error;
865 }
866
867 return 0;
868}
869
870/**
871 * sysc_check_registers - check for misconfigured register overlaps
872 * @ddata: device driver data
873 */
874static int sysc_check_registers(struct sysc *ddata)
875{
876 int i, j, nr_regs = 0, nr_matches = 0;
877
878 for (i = 0; i < SYSC_MAX_REGS; i++) {
879 if (ddata->offsets[i] < 0)
880 continue;
881
882 if (ddata->offsets[i] > (ddata->module_size - 4)) {
883 dev_err(ddata->dev, "register outside module range");
884
885 return -EINVAL;
886 }
887
888 for (j = 0; j < SYSC_MAX_REGS; j++) {
889 if (ddata->offsets[j] < 0)
890 continue;
891
892 if (ddata->offsets[i] == ddata->offsets[j])
893 nr_matches++;
894 }
895 nr_regs++;
896 }
897
Tony Lindgren0eecc632017-10-10 14:23:43 -0700898 if (nr_matches > nr_regs) {
899 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
900 nr_regs, nr_matches);
901
902 return -EINVAL;
903 }
904
905 return 0;
906}
907
908/**
Lee Jones4e001852021-05-26 09:10:37 +0100909 * sysc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700910 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700911 *
912 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700913 * within the interconnect target module range. For example, SGX has
914 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
915 * has them at offset 0x1200 in the CPSW_WR child. Usually the
916 * the interconnect target module registers are at the beginning of
917 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700918 */
919static int sysc_ioremap(struct sysc *ddata)
920{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700921 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700922
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700923 if (ddata->offsets[SYSC_REVISION] < 0 &&
924 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
925 ddata->offsets[SYSC_SYSSTATUS] < 0) {
926 size = ddata->module_size;
927 } else {
928 size = max3(ddata->offsets[SYSC_REVISION],
929 ddata->offsets[SYSC_SYSCONFIG],
930 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700931
Tony Lindgren4e23be42019-06-10 04:48:05 -0700932 if (size < SZ_1K)
933 size = SZ_1K;
934
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700935 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700936 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700937 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700938
Tony Lindgren0eecc632017-10-10 14:23:43 -0700939 ddata->module_va = devm_ioremap(ddata->dev,
940 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700941 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700942 if (!ddata->module_va)
943 return -EIO;
944
945 return 0;
946}
947
948/**
949 * sysc_map_and_check_registers - ioremap and check device registers
950 * @ddata: device driver data
951 */
952static int sysc_map_and_check_registers(struct sysc *ddata)
953{
Tony Lindgren29281352020-11-16 12:57:13 +0200954 struct device_node *np = ddata->dev->of_node;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700955 int error;
956
957 error = sysc_parse_and_check_child_range(ddata);
958 if (error)
959 return error;
960
Tony Lindgren4700a002021-03-08 11:35:07 +0200961 error = sysc_defer_non_critical(ddata);
962 if (error)
963 return error;
964
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530965 sysc_check_children(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700966
Tony Lindgren7bad5af2021-03-08 11:35:06 +0200967 if (!of_get_property(np, "reg", NULL))
968 return 0;
969
Tony Lindgren0eecc632017-10-10 14:23:43 -0700970 error = sysc_parse_registers(ddata);
971 if (error)
972 return error;
973
974 error = sysc_ioremap(ddata);
975 if (error)
976 return error;
977
978 error = sysc_check_registers(ddata);
979 if (error)
980 return error;
981
982 return 0;
983}
984
985/**
986 * sysc_show_rev - read and show interconnect target module revision
987 * @bufp: buffer to print the information to
988 * @ddata: device driver data
989 */
990static int sysc_show_rev(char *bufp, struct sysc *ddata)
991{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800992 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700993
994 if (ddata->offsets[SYSC_REVISION] < 0)
995 return sprintf(bufp, ":NA");
996
Tony Lindgren566a9b052017-12-15 09:41:19 -0800997 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700998
999 return len;
1000}
1001
1002static int sysc_show_reg(struct sysc *ddata,
1003 char *bufp, enum sysc_registers reg)
1004{
1005 if (ddata->offsets[reg] < 0)
1006 return sprintf(bufp, ":NA");
1007
1008 return sprintf(bufp, ":%x", ddata->offsets[reg]);
1009}
1010
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001011static int sysc_show_name(char *bufp, struct sysc *ddata)
1012{
1013 if (!ddata->name)
1014 return 0;
1015
1016 return sprintf(bufp, ":%s", ddata->name);
1017}
1018
Tony Lindgren0eecc632017-10-10 14:23:43 -07001019/**
1020 * sysc_show_registers - show information about interconnect target module
1021 * @ddata: device driver data
1022 */
1023static void sysc_show_registers(struct sysc *ddata)
1024{
1025 char buf[128];
1026 char *bufp = buf;
1027 int i;
1028
1029 for (i = 0; i < SYSC_MAX_REGS; i++)
1030 bufp += sysc_show_reg(ddata, bufp, i);
1031
1032 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001033 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001034
1035 dev_dbg(ddata->dev, "%llx:%x%s\n",
1036 ddata->module_pa, ddata->module_size,
1037 buf);
1038}
1039
Tony Lindgrene8639e12020-02-24 12:58:03 -08001040/**
1041 * sysc_write_sysconfig - handle sysconfig quirks for register write
1042 * @ddata: device driver data
1043 * @value: register value
1044 */
1045static void sysc_write_sysconfig(struct sysc *ddata, u32 value)
1046{
1047 if (ddata->module_unlock_quirk)
1048 ddata->module_unlock_quirk(ddata);
1049
1050 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], value);
1051
1052 if (ddata->module_lock_quirk)
1053 ddata->module_lock_quirk(ddata);
1054}
1055
Roger Quadrosd59b6052019-04-08 12:52:39 +03001056#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001057#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +03001058
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001059/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001060static int sysc_enable_module(struct device *dev)
1061{
1062 struct sysc *ddata;
1063 const struct sysc_regbits *regbits;
1064 u32 reg, idlemodes, best_mode;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001065 int error;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001066
1067 ddata = dev_get_drvdata(dev);
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001068
1069 /*
1070 * Some modules like DSS reset automatically on idle. Enable optional
1071 * reset clocks and wait for OCP softreset to complete.
1072 */
1073 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET) {
1074 error = sysc_enable_opt_clocks(ddata);
1075 if (error) {
1076 dev_err(ddata->dev,
1077 "Optional clocks failed for enable: %i\n",
1078 error);
1079 return error;
1080 }
1081 }
Tony Lindgrene275d212020-10-26 10:08:47 +02001082 /*
1083 * Some modules like i2c and hdq1w have unusable reset status unless
1084 * the module reset quirk is enabled. Skip status check on enable.
1085 */
1086 if (!(ddata->cfg.quirks & SYSC_MODULE_QUIRK_ENA_RESETDONE)) {
1087 error = sysc_wait_softreset(ddata);
1088 if (error)
1089 dev_warn(ddata->dev, "OCP softreset timed out\n");
1090 }
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001091 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET)
1092 sysc_disable_opt_clocks(ddata);
1093
1094 /*
1095 * Some subsystem private interconnects, like DSS top level module,
1096 * need only the automatic OCP softreset handling with no sysconfig
1097 * register bits to configure.
1098 */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001099 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1100 return 0;
1101
Roger Quadrosd59b6052019-04-08 12:52:39 +03001102 regbits = ddata->cap->regbits;
1103 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1104
Tony Lindgren08b91dd2020-05-31 12:37:54 -07001105 /*
1106 * Set CLOCKACTIVITY, we only use it for ick. And we only configure it
1107 * based on the SYSC_QUIRK_USE_CLOCKACT flag, not based on the hardware
1108 * capabilities. See the old HWMOD_SET_DEFAULT_CLOCKACT flag.
1109 */
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001110 if (regbits->clkact_shift >= 0 &&
Tony Lindgren08b91dd2020-05-31 12:37:54 -07001111 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT))
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001112 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
1113
Roger Quadrosd59b6052019-04-08 12:52:39 +03001114 /* Set SIDLE mode */
1115 idlemodes = ddata->cfg.sidlemodes;
1116 if (!idlemodes || regbits->sidle_shift < 0)
1117 goto set_midle;
1118
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001119 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
1120 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
1121 best_mode = SYSC_IDLE_NO;
1122 } else {
1123 best_mode = fls(ddata->cfg.sidlemodes) - 1;
1124 if (best_mode > SYSC_IDLE_MASK) {
1125 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1126 return -EINVAL;
1127 }
Tony Lindgren6e09f492019-05-27 04:51:55 -07001128
1129 /* Set WAKEUP */
1130 if (regbits->enwkup_shift >= 0 &&
1131 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
1132 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001133 }
1134
1135 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1136 reg |= best_mode << regbits->sidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001137 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001138
1139set_midle:
1140 /* Set MIDLE mode */
1141 idlemodes = ddata->cfg.midlemodes;
1142 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -07001143 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001144
1145 best_mode = fls(ddata->cfg.midlemodes) - 1;
1146 if (best_mode > SYSC_IDLE_MASK) {
1147 dev_err(dev, "%s: invalid midlemode\n", __func__);
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001148 error = -EINVAL;
1149 goto save_context;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001150 }
1151
Tony Lindgren03856e92019-10-21 13:36:09 -07001152 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_MSTANDBY)
1153 best_mode = SYSC_IDLE_NO;
1154
Roger Quadrosd59b6052019-04-08 12:52:39 +03001155 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1156 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001157 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001158
Tony Lindgreneec26552019-05-27 04:51:54 -07001159set_autoidle:
1160 /* Autoidle bit must enabled separately if available */
1161 if (regbits->autoidle_shift >= 0 &&
1162 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
1163 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001164 sysc_write_sysconfig(ddata, reg);
Tony Lindgreneec26552019-05-27 04:51:54 -07001165 }
1166
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001167 error = 0;
1168
1169save_context:
1170 /* Save context and flush posted write */
1171 ddata->sysconfig = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
Tony Lindgren5ce8aee2020-05-27 06:49:29 -07001172
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001173 if (ddata->module_enable_quirk)
1174 ddata->module_enable_quirk(ddata);
1175
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001176 return error;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001177}
1178
1179static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
1180{
1181 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
1182 *best_mode = SYSC_IDLE_SMART_WKUP;
1183 else if (idlemodes & BIT(SYSC_IDLE_SMART))
1184 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -07001185 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +03001186 *best_mode = SYSC_IDLE_FORCE;
1187 else
1188 return -EINVAL;
1189
1190 return 0;
1191}
1192
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001193/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001194static int sysc_disable_module(struct device *dev)
1195{
1196 struct sysc *ddata;
1197 const struct sysc_regbits *regbits;
1198 u32 reg, idlemodes, best_mode;
1199 int ret;
1200
1201 ddata = dev_get_drvdata(dev);
1202 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1203 return 0;
1204
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001205 if (ddata->module_disable_quirk)
1206 ddata->module_disable_quirk(ddata);
1207
Roger Quadrosd59b6052019-04-08 12:52:39 +03001208 regbits = ddata->cap->regbits;
1209 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1210
1211 /* Set MIDLE mode */
1212 idlemodes = ddata->cfg.midlemodes;
1213 if (!idlemodes || regbits->midle_shift < 0)
1214 goto set_sidle;
1215
1216 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1217 if (ret) {
1218 dev_err(dev, "%s: invalid midlemode\n", __func__);
1219 return ret;
1220 }
1221
Tony Lindgren93c60482019-12-09 13:55:15 -08001222 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_MSTANDBY) ||
1223 ddata->cfg.quirks & (SYSC_QUIRK_FORCE_MSTANDBY))
Tony Lindgren03856e92019-10-21 13:36:09 -07001224 best_mode = SYSC_IDLE_FORCE;
1225
Roger Quadrosd59b6052019-04-08 12:52:39 +03001226 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1227 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001228 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001229
1230set_sidle:
1231 /* Set SIDLE mode */
1232 idlemodes = ddata->cfg.sidlemodes;
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001233 if (!idlemodes || regbits->sidle_shift < 0) {
1234 ret = 0;
1235 goto save_context;
1236 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001237
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001238 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
1239 best_mode = SYSC_IDLE_FORCE;
1240 } else {
1241 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1242 if (ret) {
1243 dev_err(dev, "%s: invalid sidlemode\n", __func__);
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001244 ret = -EINVAL;
1245 goto save_context;
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001246 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001247 }
1248
1249 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1250 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -07001251 if (regbits->autoidle_shift >= 0 &&
1252 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1253 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001254 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001255
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001256 ret = 0;
Tony Lindgren5ce8aee2020-05-27 06:49:29 -07001257
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001258save_context:
1259 /* Save context and flush posted write */
1260 ddata->sysconfig = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1261
1262 return ret;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001263}
1264
Tony Lindgrenff437282019-03-21 11:00:21 -07001265static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1266 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001267{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001268 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001269 int error;
1270
1271 pdata = dev_get_platdata(ddata->dev);
1272 if (!pdata)
1273 return 0;
1274
1275 if (!pdata->idle_module)
1276 return -ENODEV;
1277
1278 error = pdata->idle_module(dev, &ddata->cookie);
1279 if (error)
1280 dev_err(dev, "%s: could not idle: %i\n",
1281 __func__, error);
1282
Tero Kristo4345f0d2019-08-07 15:46:04 +03001283 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001284
Tony Lindgrenff437282019-03-21 11:00:21 -07001285 return 0;
1286}
1287
1288static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1289 struct sysc *ddata)
1290{
1291 struct ti_sysc_platform_data *pdata;
1292 int error;
1293
1294 pdata = dev_get_platdata(ddata->dev);
1295 if (!pdata)
1296 return 0;
1297
1298 if (!pdata->enable_module)
1299 return -ENODEV;
1300
1301 error = pdata->enable_module(dev, &ddata->cookie);
1302 if (error)
1303 dev_err(dev, "%s: could not enable: %i\n",
1304 __func__, error);
1305
Tero Kristobf59ebb2019-10-07 15:29:29 +03001306 reset_control_deassert(ddata->rsts);
1307
Tony Lindgrenff437282019-03-21 11:00:21 -07001308 return 0;
1309}
1310
1311static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1312{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001313 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001314 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001315
1316 ddata = dev_get_drvdata(dev);
1317
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001318 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001319 return 0;
1320
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001321 sysc_clkdm_deny_idle(ddata);
1322
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001323 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001324 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001325 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001326 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001327 } else {
1328 error = sysc_disable_module(dev);
1329 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001330 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001331 }
1332
Tony Lindgrend8789702019-03-21 11:00:21 -07001333 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001334
Tony Lindgrend8789702019-03-21 11:00:21 -07001335 if (sysc_opt_clks_needed(ddata))
1336 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001337
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001338 ddata->enabled = false;
1339
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001340err_allow_idle:
Tero Kristob6036312019-08-07 15:46:03 +03001341 sysc_clkdm_allow_idle(ddata);
1342
Tony Lindgren4097c9a2020-11-16 12:57:13 +02001343 reset_control_assert(ddata->rsts);
1344
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001345 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001346}
1347
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001348static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001349{
1350 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001351 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001352
1353 ddata = dev_get_drvdata(dev);
1354
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001355 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001356 return 0;
1357
Tony Lindgren8383e252019-05-27 04:51:56 -07001358
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001359 sysc_clkdm_deny_idle(ddata);
1360
Tony Lindgrend8789702019-03-21 11:00:21 -07001361 if (sysc_opt_clks_needed(ddata)) {
1362 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001363 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001364 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001365 }
1366
Tony Lindgrend8789702019-03-21 11:00:21 -07001367 error = sysc_enable_main_clocks(ddata);
1368 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001369 goto err_opt_clocks;
1370
Tero Kristobf59ebb2019-10-07 15:29:29 +03001371 reset_control_deassert(ddata->rsts);
1372
Tony Lindgren93de83a2019-03-21 11:00:21 -07001373 if (ddata->legacy_mode) {
1374 error = sysc_runtime_resume_legacy(dev, ddata);
1375 if (error)
1376 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001377 } else {
1378 error = sysc_enable_module(dev);
1379 if (error)
1380 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001381 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001382
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001383 ddata->enabled = true;
1384
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001385 sysc_clkdm_allow_idle(ddata);
1386
Tony Lindgrend8789702019-03-21 11:00:21 -07001387 return 0;
1388
1389err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001390 sysc_disable_main_clocks(ddata);
1391err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001392 if (sysc_opt_clks_needed(ddata))
1393 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001394err_allow_idle:
1395 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001396
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001397 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001398}
1399
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001400/*
1401 * Checks if device context was lost. Assumes the sysconfig register value
1402 * after lost context is different from the configured value. Only works for
1403 * enabled devices.
1404 *
1405 * Eventually we may want to also add support to using the context lost
1406 * registers that some SoCs have.
1407 */
1408static int sysc_check_context(struct sysc *ddata)
1409{
1410 u32 reg;
1411
1412 if (!ddata->enabled)
1413 return -ENODATA;
1414
1415 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1416 if (reg == ddata->sysconfig)
1417 return 0;
1418
1419 return -EACCES;
1420}
1421
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001422static int sysc_reinit_module(struct sysc *ddata, bool leave_enabled)
1423{
1424 struct device *dev = ddata->dev;
1425 int error;
1426
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001427 if (ddata->enabled) {
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001428 /* Nothing to do if enabled and context not lost */
1429 error = sysc_check_context(ddata);
1430 if (!error)
1431 return 0;
1432
1433 /* Disable target module if it is enabled */
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001434 error = sysc_runtime_suspend(dev);
1435 if (error)
1436 dev_warn(dev, "reinit suspend failed: %i\n", error);
1437 }
1438
1439 /* Enable target module */
1440 error = sysc_runtime_resume(dev);
1441 if (error)
1442 dev_warn(dev, "reinit resume failed: %i\n", error);
1443
Tony Lindgren6a52bc22021-09-21 12:42:25 +03001444 /* Some modules like am335x gpmc need reset and restore of sysconfig */
1445 if (ddata->cfg.quirks & SYSC_QUIRK_RESET_ON_CTX_LOST) {
1446 error = sysc_reset(ddata);
1447 if (error)
1448 dev_warn(dev, "reinit reset failed: %i\n", error);
1449
1450 sysc_write_sysconfig(ddata, ddata->sysconfig);
1451 }
1452
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001453 if (leave_enabled)
1454 return error;
1455
1456 /* Disable target module if no leave_enabled was set */
1457 error = sysc_runtime_suspend(dev);
1458 if (error)
1459 dev_warn(dev, "reinit suspend failed: %i\n", error);
1460
1461 return error;
1462}
1463
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001464static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001465{
1466 struct sysc *ddata;
1467
1468 ddata = dev_get_drvdata(dev);
1469
Tony Lindgrena55de412020-07-02 13:57:14 -07001470 if (ddata->cfg.quirks &
1471 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
Tony Lindgrene7420c22018-04-16 10:26:46 -07001472 return 0;
1473
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001474 if (!ddata->enabled)
1475 return 0;
1476
1477 ddata->needs_resume = 1;
1478
1479 return sysc_runtime_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001480}
1481
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001482static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001483{
1484 struct sysc *ddata;
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001485 int error = 0;
Tony Lindgren62020f22018-02-22 13:59:44 -08001486
1487 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001488
Tony Lindgrena55de412020-07-02 13:57:14 -07001489 if (ddata->cfg.quirks &
1490 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
Tony Lindgrene7420c22018-04-16 10:26:46 -07001491 return 0;
1492
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001493 if (ddata->cfg.quirks & SYSC_QUIRK_REINIT_ON_RESUME) {
1494 error = sysc_reinit_module(ddata, ddata->needs_resume);
1495 if (error)
1496 dev_warn(dev, "noirq_resume failed: %i\n", error);
1497 } else if (ddata->needs_resume) {
1498 error = sysc_runtime_resume(dev);
1499 if (error)
1500 dev_warn(dev, "noirq_resume failed: %i\n", error);
1501 }
1502
1503 ddata->needs_resume = 0;
1504
1505 return error;
Tony Lindgrene7420c22018-04-16 10:26:46 -07001506}
1507
Tony Lindgren0eecc632017-10-10 14:23:43 -07001508static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001509 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001510 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1511 sysc_runtime_resume,
1512 NULL)
1513};
1514
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001515/* Module revision register based quirks */
1516struct sysc_revision_quirk {
1517 const char *name;
1518 u32 base;
1519 int rev_offset;
1520 int sysc_offset;
1521 int syss_offset;
1522 u32 revision;
1523 u32 revision_mask;
1524 u32 quirks;
1525};
1526
1527#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1528 optrev_val, optrevmask, optquirkmask) \
1529 { \
1530 .name = (optname), \
1531 .base = (optbase), \
1532 .rev_offset = (optrev), \
1533 .sysc_offset = (optsysc), \
1534 .syss_offset = (optsyss), \
1535 .revision = (optrev_val), \
1536 .revision_mask = (optrevmask), \
1537 .quirks = (optquirkmask), \
1538 }
1539
1540static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1541 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001542 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1543 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001544 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1545 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001546 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001547 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001548 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001549 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001550 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001551 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001552 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001553
Tony Lindgrena54275f2019-03-21 11:00:21 -07001554 /* Quirks that need to be set based on the module address */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001555 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -ENODEV, 0x50000800, 0xffffffff,
Tony Lindgrena54275f2019-03-21 11:00:21 -07001556 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1557 SYSC_QUIRK_SWSUP_SIDLE),
1558
Tony Lindgren4e23be42019-06-10 04:48:05 -07001559 /* Quirks that need to be set based on detected module */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001560 SYSC_QUIRK("aess", 0, 0, 0x10, -ENODEV, 0x40000000, 0xffffffff,
Tony Lindgren020003f2019-11-14 08:25:28 -08001561 SYSC_MODULE_QUIRK_AESS),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001562 SYSC_QUIRK("dcan", 0x48480000, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001563 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001564 SYSC_QUIRK("dss", 0x4832a000, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001565 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001566 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000040, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001567 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001568 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000061, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001569 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001570 SYSC_QUIRK("dwc3", 0x48880000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001571 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001572 SYSC_QUIRK("dwc3", 0x488c0000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001573 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren1b99c1e2021-09-21 12:42:25 +03001574 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
1575 SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrencfeeea62020-11-16 12:57:13 +02001576 SYSC_QUIRK("gpmc", 0, 0, 0x10, 0x14, 0x00000060, 0xffffffff,
Tony Lindgrend48dca52021-09-21 12:42:25 +03001577 SYSC_QUIRK_REINIT_ON_CTX_LOST | SYSC_QUIRK_RESET_ON_CTX_LOST |
Tony Lindgrencfeeea62020-11-16 12:57:13 +02001578 SYSC_QUIRK_GPMC_DEBUG),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001579 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50030200, 0xffffffff,
1580 SYSC_QUIRK_OPT_CLKS_NEEDED),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001581 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001582 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001583 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001584 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001585 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001586 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001587 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001588 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001589 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001590 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001591 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
Tony Lindgrene275d212020-10-26 10:08:47 +02001592 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001593 SYSC_QUIRK("gpu", 0x50000000, 0x14, -ENODEV, -ENODEV, 0x00010201, 0xffffffff, 0),
1594 SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff,
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001595 SYSC_MODULE_QUIRK_SGX),
Tony Lindgrenaef067e2020-03-10 09:06:02 -07001596 SYSC_QUIRK("lcdc", 0, 0, 0x54, -ENODEV, 0x4f201000, 0xffffffff,
1597 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Peter Ujfalusi8122dc52021-07-17 15:09:24 +03001598 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44306302, 0xffffffff,
1599 SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgrene8639e12020-02-24 12:58:03 -08001600 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -ENODEV, 0x4eb01908, 0xffff00f0,
1601 SYSC_MODULE_QUIRK_RTC_UNLOCK),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001602 SYSC_QUIRK("tptc", 0, 0, 0x10, -ENODEV, 0x40006c00, 0xffffefff,
1603 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1604 SYSC_QUIRK("tptc", 0, 0, -ENODEV, -ENODEV, 0x40007c00, 0xffffffff,
1605 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgrendb8e7122021-05-07 12:09:03 +03001606 SYSC_QUIRK("sata", 0, 0xfc, 0x1100, -ENODEV, 0x5e412000, 0xffffffff,
1607 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren42546322020-07-13 09:59:47 -07001608 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff,
1609 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1610 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -ENODEV, 0x50700101, 0xffffffff,
1611 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren03856e92019-10-21 13:36:09 -07001612 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
Tony Lindgren5c99fa72021-09-21 12:42:25 +03001613 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
1614 SYSC_MODULE_QUIRK_OTG),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001615 SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -ENODEV, 0x4ea2080d, 0xffffffff,
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001616 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
Tony Lindgren90678392021-09-21 12:42:25 +03001617 SYSC_QUIRK_REINIT_ON_CTX_LOST),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001618 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1619 SYSC_MODULE_QUIRK_WDT),
Suman Annab2745d92020-02-27 16:28:34 -06001620 /* PRUSS on am3, am4 and am5 */
1621 SYSC_QUIRK("pruss", 0, 0x26000, 0x26004, -ENODEV, 0x47000000, 0xff000000,
1622 SYSC_MODULE_QUIRK_PRUSS),
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001623 /* Watchdog on am3 and am4 */
1624 SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1625 SYSC_MODULE_QUIRK_WDT | SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001626
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001627#ifdef DEBUG
Tony Lindgren590e15c2020-02-24 12:58:03 -08001628 SYSC_QUIRK("adc", 0, 0, 0x10, -ENODEV, 0x47300001, 0xffffffff, 0),
1629 SYSC_QUIRK("atl", 0, 0, -ENODEV, -ENODEV, 0x0a070100, 0xffffffff, 0),
1630 SYSC_QUIRK("cm", 0, 0, -ENODEV, -ENODEV, 0x40000301, 0xffffffff, 0),
1631 SYSC_QUIRK("control", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001632 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001633 0xffff00f0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001634 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff, 0),
1635 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001636 SYSC_QUIRK("dispc", 0x4832a400, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1637 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1638 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000051, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001639 SYSC_QUIRK("dmic", 0, 0, 0x10, -ENODEV, 0x50010000, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001640 SYSC_QUIRK("dsi", 0x58004000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1641 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1642 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1643 SYSC_QUIRK("dsi", 0x58009000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001644 SYSC_QUIRK("dwc3", 0, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, 0),
Tony Lindgren7edd00f2019-08-14 05:18:16 -07001645 SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1646 SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001647 SYSC_QUIRK("elm", 0x48080000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
1648 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x40441403, 0xffff0fff, 0),
1649 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x50440500, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001650 SYSC_QUIRK("epwmss", 0, 0, 0x4, -ENODEV, 0x47400001, 0xffffffff, 0),
1651 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -ENODEV, 0, 0, 0),
1652 SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001653 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50031d00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001654 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001655 SYSC_QUIRK("iss", 0, 0, 0x10, -ENODEV, 0x40000101, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001656 SYSC_QUIRK("keypad", 0x4a31c000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001657 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44307b02, 0xffffffff, 0),
1658 SYSC_QUIRK("mcbsp", 0, -ENODEV, 0x8c, -ENODEV, 0, 0, 0),
1659 SYSC_QUIRK("mcspi", 0, 0, 0x10, -ENODEV, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001660 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001661 SYSC_QUIRK("mailbox", 0, 0, 0x10, -ENODEV, 0x00000400, 0xffffffff, 0),
1662 SYSC_QUIRK("m3", 0, 0, -ENODEV, -ENODEV, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001663 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001664 SYSC_QUIRK("ocp2scp", 0, 0, -ENODEV, -ENODEV, 0x50060007, 0xffffffff, 0),
1665 SYSC_QUIRK("padconf", 0, 0, 0x10, -ENODEV, 0x4fff0800, 0xffffffff, 0),
1666 SYSC_QUIRK("padconf", 0, 0, -ENODEV, -ENODEV, 0x40001100, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001667 SYSC_QUIRK("pcie", 0x51000000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
1668 SYSC_QUIRK("pcie", 0x51800000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001669 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000100, 0xffffffff, 0),
1670 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x00004102, 0xffffffff, 0),
1671 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000400, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001672 SYSC_QUIRK("rfbi", 0x4832a800, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1673 SYSC_QUIRK("rfbi", 0x58002000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001674 SYSC_QUIRK("scm", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
1675 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4e8b0100, 0xffffffff, 0),
1676 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4f000100, 0xffffffff, 0),
1677 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x40000900, 0xffffffff, 0),
1678 SYSC_QUIRK("scrm", 0, 0, -ENODEV, -ENODEV, 0x00000010, 0xffffffff, 0),
1679 SYSC_QUIRK("sdio", 0, 0, 0x10, -ENODEV, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001680 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001681 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001682 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40000902, 0xffffffff, 0),
1683 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40002903, 0xffffffff, 0),
Tony Lindgrened4520d2021-08-09 11:27:47 -05001684 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x24, -ENODEV, 0x00000000, 0xffffffff, 0),
1685 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x38, -ENODEV, 0x00000000, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001686 SYSC_QUIRK("spinlock", 0, 0, 0x10, -ENODEV, 0x50020000, 0xffffffff, 0),
1687 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -ENODEV, 0x00000020, 0xffffffff, 0),
Tony Lindgren1a542812020-05-07 09:43:08 -07001688 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000013, 0xffffffff, 0),
1689 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff, 0),
1690 /* Some timers on omap4 and later */
1691 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x50002100, 0xffffffff, 0),
1692 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x4fff1301, 0xffff00ff, 0),
1693 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000040, 0xffffffff, 0),
1694 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000011, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001695 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000060, 0xffffffff, 0),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001696 SYSC_QUIRK("tpcc", 0, 0, -ENODEV, -ENODEV, 0x40014c00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001697 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001698 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001699 SYSC_QUIRK("venc", 0x58003000, 0, -ENODEV, -ENODEV, 0x00000002, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001700 SYSC_QUIRK("vfpe", 0, 0, 0x104, -ENODEV, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001701#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001702};
1703
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001704/*
1705 * Early quirks based on module base and register offsets only that are
1706 * needed before the module revision can be read
1707 */
1708static void sysc_init_early_quirks(struct sysc *ddata)
1709{
1710 const struct sysc_revision_quirk *q;
1711 int i;
1712
1713 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1714 q = &sysc_revision_quirks[i];
1715
1716 if (!q->base)
1717 continue;
1718
1719 if (q->base != ddata->module_pa)
1720 continue;
1721
Tony Lindgren590e15c2020-02-24 12:58:03 -08001722 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001723 continue;
1724
Tony Lindgren590e15c2020-02-24 12:58:03 -08001725 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001726 continue;
1727
Tony Lindgren590e15c2020-02-24 12:58:03 -08001728 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001729 continue;
1730
1731 ddata->name = q->name;
1732 ddata->cfg.quirks |= q->quirks;
1733 }
1734}
1735
1736/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001737static void sysc_init_revision_quirks(struct sysc *ddata)
1738{
1739 const struct sysc_revision_quirk *q;
1740 int i;
1741
1742 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1743 q = &sysc_revision_quirks[i];
1744
1745 if (q->base && q->base != ddata->module_pa)
1746 continue;
1747
Tony Lindgren590e15c2020-02-24 12:58:03 -08001748 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001749 continue;
1750
Tony Lindgren590e15c2020-02-24 12:58:03 -08001751 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001752 continue;
1753
Tony Lindgren590e15c2020-02-24 12:58:03 -08001754 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001755 continue;
1756
1757 if (q->revision == ddata->revision ||
1758 (q->revision & q->revision_mask) ==
1759 (ddata->revision & q->revision_mask)) {
1760 ddata->name = q->name;
1761 ddata->cfg.quirks |= q->quirks;
1762 }
1763 }
1764}
1765
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001766/*
1767 * DSS needs dispc outputs disabled to reset modules. Returns mask of
1768 * enabled DSS interrupts. Eventually we may be able to do this on
1769 * dispc init rather than top-level DSS init.
1770 */
1771static u32 sysc_quirk_dispc(struct sysc *ddata, int dispc_offset,
1772 bool disable)
1773{
1774 bool lcd_en, digit_en, lcd2_en = false, lcd3_en = false;
1775 const int lcd_en_mask = BIT(0), digit_en_mask = BIT(1);
1776 int manager_count;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001777 bool framedonetv_irq = true;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001778 u32 val, irq_mask = 0;
1779
1780 switch (sysc_soc->soc) {
1781 case SOC_2420 ... SOC_3630:
1782 manager_count = 2;
1783 framedonetv_irq = false;
1784 break;
1785 case SOC_4430 ... SOC_4470:
1786 manager_count = 3;
1787 break;
1788 case SOC_5430:
1789 case SOC_DRA7:
1790 manager_count = 4;
1791 break;
1792 case SOC_AM4:
1793 manager_count = 1;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001794 framedonetv_irq = false;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001795 break;
1796 case SOC_UNKNOWN:
1797 default:
1798 return 0;
Yang Li52fbb5a2021-02-02 15:00:05 +08001799 }
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001800
1801 /* Remap the whole module range to be able to reset dispc outputs */
1802 devm_iounmap(ddata->dev, ddata->module_va);
1803 ddata->module_va = devm_ioremap(ddata->dev,
1804 ddata->module_pa,
1805 ddata->module_size);
1806 if (!ddata->module_va)
1807 return -EIO;
1808
1809 /* DISP_CONTROL */
1810 val = sysc_read(ddata, dispc_offset + 0x40);
1811 lcd_en = val & lcd_en_mask;
1812 digit_en = val & digit_en_mask;
1813 if (lcd_en)
1814 irq_mask |= BIT(0); /* FRAMEDONE */
1815 if (digit_en) {
1816 if (framedonetv_irq)
1817 irq_mask |= BIT(24); /* FRAMEDONETV */
1818 else
1819 irq_mask |= BIT(2) | BIT(3); /* EVSYNC bits */
1820 }
1821 if (disable & (lcd_en | digit_en))
1822 sysc_write(ddata, dispc_offset + 0x40,
1823 val & ~(lcd_en_mask | digit_en_mask));
1824
1825 if (manager_count <= 2)
1826 return irq_mask;
1827
1828 /* DISPC_CONTROL2 */
1829 val = sysc_read(ddata, dispc_offset + 0x238);
1830 lcd2_en = val & lcd_en_mask;
1831 if (lcd2_en)
1832 irq_mask |= BIT(22); /* FRAMEDONE2 */
1833 if (disable && lcd2_en)
1834 sysc_write(ddata, dispc_offset + 0x238,
1835 val & ~lcd_en_mask);
1836
1837 if (manager_count <= 3)
1838 return irq_mask;
1839
1840 /* DISPC_CONTROL3 */
1841 val = sysc_read(ddata, dispc_offset + 0x848);
1842 lcd3_en = val & lcd_en_mask;
1843 if (lcd3_en)
1844 irq_mask |= BIT(30); /* FRAMEDONE3 */
1845 if (disable && lcd3_en)
1846 sysc_write(ddata, dispc_offset + 0x848,
1847 val & ~lcd_en_mask);
1848
1849 return irq_mask;
1850}
1851
1852/* DSS needs child outputs disabled and SDI registers cleared for reset */
1853static void sysc_pre_reset_quirk_dss(struct sysc *ddata)
1854{
1855 const int dispc_offset = 0x1000;
1856 int error;
1857 u32 irq_mask, val;
1858
1859 /* Get enabled outputs */
1860 irq_mask = sysc_quirk_dispc(ddata, dispc_offset, false);
1861 if (!irq_mask)
1862 return;
1863
1864 /* Clear IRQSTATUS */
Tony Lindgren69e60902020-03-03 07:17:43 -08001865 sysc_write(ddata, dispc_offset + 0x18, irq_mask);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001866
1867 /* Disable outputs */
1868 val = sysc_quirk_dispc(ddata, dispc_offset, true);
1869
1870 /* Poll IRQSTATUS */
1871 error = readl_poll_timeout(ddata->module_va + dispc_offset + 0x18,
1872 val, val != irq_mask, 100, 50);
1873 if (error)
1874 dev_warn(ddata->dev, "%s: timed out %08x !+ %08x\n",
1875 __func__, val, irq_mask);
1876
1877 if (sysc_soc->soc == SOC_3430) {
1878 /* Clear DSS_SDI_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001879 sysc_write(ddata, 0x44, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001880
1881 /* Clear DSS_PLL_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001882 sysc_write(ddata, 0x48, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001883 }
1884
1885 /* Clear DSS_CONTROL to switch DSS clock sources to PRCM if not */
Tony Lindgren69e60902020-03-03 07:17:43 -08001886 sysc_write(ddata, 0x40, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001887}
1888
Tony Lindgren4e23be42019-06-10 04:48:05 -07001889/* 1-wire needs module's internal clocks enabled for reset */
Tony Lindgrenaec551c2020-02-24 12:58:03 -08001890static void sysc_pre_reset_quirk_hdq1w(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001891{
1892 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1893 u16 val;
1894
1895 val = sysc_read(ddata, offset);
1896 val |= BIT(5);
1897 sysc_write(ddata, offset, val);
1898}
1899
Tony Lindgren020003f2019-11-14 08:25:28 -08001900/* AESS (Audio Engine SubSystem) needs autogating set after enable */
1901static void sysc_module_enable_quirk_aess(struct sysc *ddata)
1902{
1903 int offset = 0x7c; /* AESS_AUTO_GATING_ENABLE */
1904
1905 sysc_write(ddata, offset, 1);
1906}
1907
Tony Lindgrene64c0212020-02-24 12:58:03 -08001908/* I2C needs to be disabled for reset */
Tony Lindgren4e23be42019-06-10 04:48:05 -07001909static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1910{
1911 int offset;
1912 u16 val;
1913
1914 /* I2C_CON, omap2/3 is different from omap4 and later */
1915 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1916 offset = 0x24;
1917 else
1918 offset = 0xa4;
1919
1920 /* I2C_EN */
1921 val = sysc_read(ddata, offset);
1922 if (enable)
1923 val |= BIT(15);
1924 else
1925 val &= ~BIT(15);
1926 sysc_write(ddata, offset, val);
1927}
1928
Tony Lindgrene64c0212020-02-24 12:58:03 -08001929static void sysc_pre_reset_quirk_i2c(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001930{
1931 sysc_clk_quirk_i2c(ddata, false);
1932}
1933
Tony Lindgrene64c0212020-02-24 12:58:03 -08001934static void sysc_post_reset_quirk_i2c(struct sysc *ddata)
1935{
1936 sysc_clk_quirk_i2c(ddata, true);
1937}
1938
Tony Lindgrene8639e12020-02-24 12:58:03 -08001939/* RTC on am3 and 4 needs to be unlocked and locked for sysconfig */
1940static void sysc_quirk_rtc(struct sysc *ddata, bool lock)
1941{
1942 u32 val, kick0_val = 0, kick1_val = 0;
1943 unsigned long flags;
1944 int error;
1945
1946 if (!lock) {
1947 kick0_val = 0x83e70b13;
1948 kick1_val = 0x95a4f1e0;
1949 }
1950
1951 local_irq_save(flags);
1952 /* RTC_STATUS BUSY bit may stay active for 1/32768 seconds (~30 usec) */
Tony Lindgrenafe6f1e2020-07-02 10:41:02 -07001953 error = readl_poll_timeout_atomic(ddata->module_va + 0x44, val,
1954 !(val & BIT(0)), 100, 50);
Tony Lindgrene8639e12020-02-24 12:58:03 -08001955 if (error)
1956 dev_warn(ddata->dev, "rtc busy timeout\n");
1957 /* Now we have ~15 microseconds to read/write various registers */
1958 sysc_write(ddata, 0x6c, kick0_val);
1959 sysc_write(ddata, 0x70, kick1_val);
1960 local_irq_restore(flags);
1961}
1962
1963static void sysc_module_unlock_quirk_rtc(struct sysc *ddata)
1964{
1965 sysc_quirk_rtc(ddata, false);
1966}
1967
1968static void sysc_module_lock_quirk_rtc(struct sysc *ddata)
1969{
1970 sysc_quirk_rtc(ddata, true);
1971}
1972
Tony Lindgren5c99fa72021-09-21 12:42:25 +03001973/* OTG omap2430 glue layer up to omap4 needs OTG_FORCESTDBY configured */
1974static void sysc_module_enable_quirk_otg(struct sysc *ddata)
1975{
1976 int offset = 0x414; /* OTG_FORCESTDBY */
1977
1978 sysc_write(ddata, offset, 0);
1979}
1980
1981static void sysc_module_disable_quirk_otg(struct sysc *ddata)
1982{
1983 int offset = 0x414; /* OTG_FORCESTDBY */
1984 u32 val = BIT(0); /* ENABLEFORCE */
1985
1986 sysc_write(ddata, offset, val);
1987}
1988
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001989/* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */
1990static void sysc_module_enable_quirk_sgx(struct sysc *ddata)
1991{
1992 int offset = 0xff08; /* OCP_DEBUG_CONFIG */
1993 u32 val = BIT(31); /* THALIA_INT_BYPASS */
1994
1995 sysc_write(ddata, offset, val);
1996}
1997
Tony Lindgren4e23be42019-06-10 04:48:05 -07001998/* Watchdog timer needs a disable sequence after reset */
1999static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
2000{
2001 int wps, spr, error;
2002 u32 val;
2003
2004 wps = 0x34;
2005 spr = 0x48;
2006
2007 sysc_write(ddata, spr, 0xaaaa);
2008 error = readl_poll_timeout(ddata->module_va + wps, val,
2009 !(val & 0x10), 100,
2010 MAX_MODULE_SOFTRESET_WAIT);
2011 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07002012 dev_warn(ddata->dev, "wdt disable step1 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07002013
Tony Lindgrenc7d86692019-10-17 11:21:44 -07002014 sysc_write(ddata, spr, 0x5555);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002015 error = readl_poll_timeout(ddata->module_va + wps, val,
2016 !(val & 0x10), 100,
2017 MAX_MODULE_SOFTRESET_WAIT);
2018 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07002019 dev_warn(ddata->dev, "wdt disable step2 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07002020}
2021
Suman Annab2745d92020-02-27 16:28:34 -06002022/* PRUSS needs to set MSTANDBY_INIT inorder to idle properly */
2023static void sysc_module_disable_quirk_pruss(struct sysc *ddata)
2024{
2025 u32 reg;
2026
2027 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
2028 reg |= SYSC_PRUSS_STANDBY_INIT;
2029 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
2030}
2031
Tony Lindgren4e23be42019-06-10 04:48:05 -07002032static void sysc_init_module_quirks(struct sysc *ddata)
2033{
2034 if (ddata->legacy_mode || !ddata->name)
2035 return;
2036
2037 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08002038 ddata->pre_reset_quirk = sysc_pre_reset_quirk_hdq1w;
Tony Lindgren4e23be42019-06-10 04:48:05 -07002039
2040 return;
2041 }
2042
Tony Lindgrencfeeea62020-11-16 12:57:13 +02002043#ifdef CONFIG_OMAP_GPMC_DEBUG
2044 if (ddata->cfg.quirks & SYSC_QUIRK_GPMC_DEBUG) {
2045 ddata->cfg.quirks |= SYSC_QUIRK_NO_RESET_ON_INIT;
2046
2047 return;
2048 }
2049#endif
2050
Tony Lindgren4e23be42019-06-10 04:48:05 -07002051 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08002052 ddata->pre_reset_quirk = sysc_pre_reset_quirk_i2c;
2053 ddata->post_reset_quirk = sysc_post_reset_quirk_i2c;
Tony Lindgren4e23be42019-06-10 04:48:05 -07002054
2055 return;
2056 }
2057
Tony Lindgren020003f2019-11-14 08:25:28 -08002058 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_AESS)
2059 ddata->module_enable_quirk = sysc_module_enable_quirk_aess;
2060
Tony Lindgren7324a7a2020-02-24 12:58:03 -08002061 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_DSS_RESET)
2062 ddata->pre_reset_quirk = sysc_pre_reset_quirk_dss;
2063
Tony Lindgrene8639e12020-02-24 12:58:03 -08002064 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_RTC_UNLOCK) {
2065 ddata->module_unlock_quirk = sysc_module_unlock_quirk_rtc;
2066 ddata->module_lock_quirk = sysc_module_lock_quirk_rtc;
2067
2068 return;
2069 }
2070
Tony Lindgren5c99fa72021-09-21 12:42:25 +03002071 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_OTG) {
2072 ddata->module_enable_quirk = sysc_module_enable_quirk_otg;
2073 ddata->module_disable_quirk = sysc_module_disable_quirk_otg;
2074 }
2075
Tony Lindgrend7f563d2019-08-14 05:18:16 -07002076 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_SGX)
2077 ddata->module_enable_quirk = sysc_module_enable_quirk_sgx;
2078
Tony Lindgrenc7d86692019-10-17 11:21:44 -07002079 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT) {
Tony Lindgren4e23be42019-06-10 04:48:05 -07002080 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
Tony Lindgrenc7d86692019-10-17 11:21:44 -07002081 ddata->module_disable_quirk = sysc_reset_done_quirk_wdt;
2082 }
Suman Annab2745d92020-02-27 16:28:34 -06002083
2084 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_PRUSS)
2085 ddata->module_disable_quirk = sysc_module_disable_quirk_pruss;
Tony Lindgren4e23be42019-06-10 04:48:05 -07002086}
2087
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002088static int sysc_clockdomain_init(struct sysc *ddata)
2089{
2090 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2091 struct clk *fck = NULL, *ick = NULL;
2092 int error;
2093
2094 if (!pdata || !pdata->init_clockdomain)
2095 return 0;
2096
2097 switch (ddata->nr_clocks) {
2098 case 2:
2099 ick = ddata->clocks[SYSC_ICK];
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002100 fallthrough;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002101 case 1:
2102 fck = ddata->clocks[SYSC_FCK];
2103 break;
2104 case 0:
2105 return 0;
2106 }
2107
2108 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
2109 if (!error || error == -ENODEV)
2110 return 0;
2111
2112 return error;
2113}
2114
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002115/*
2116 * Note that pdata->init_module() typically does a reset first. After
2117 * pdata->init_module() is done, PM runtime can be used for the interconnect
2118 * target module.
2119 */
2120static int sysc_legacy_init(struct sysc *ddata)
2121{
2122 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2123 int error;
2124
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002125 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002126 return 0;
2127
2128 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
2129 if (error == -EEXIST)
2130 error = 0;
2131
2132 return error;
2133}
2134
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002135/*
2136 * Note that the caller must ensure the interconnect target module is enabled
2137 * before calling reset. Otherwise reset will not complete.
2138 */
Faiz Abbas596e7952018-07-09 22:18:39 +05302139static int sysc_reset(struct sysc *ddata)
2140{
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002141 int sysc_offset, sysc_val, error;
2142 u32 sysc_mask;
Faiz Abbas596e7952018-07-09 22:18:39 +05302143
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002144 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002145
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002146 if (ddata->legacy_mode ||
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002147 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05302148 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
2149 return 0;
2150
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002151 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05302152
Tony Lindgrene64c0212020-02-24 12:58:03 -08002153 if (ddata->pre_reset_quirk)
2154 ddata->pre_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002155
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002156 if (sysc_offset >= 0) {
2157 sysc_val = sysc_read_sysconfig(ddata);
2158 sysc_val |= sysc_mask;
2159 sysc_write(ddata, sysc_offset, sysc_val);
2160 }
Faiz Abbas596e7952018-07-09 22:18:39 +05302161
Tony Lindgrene709ed72019-12-12 08:20:10 -08002162 if (ddata->cfg.srst_udelay)
2163 usleep_range(ddata->cfg.srst_udelay,
2164 ddata->cfg.srst_udelay * 2);
2165
Tony Lindgrene64c0212020-02-24 12:58:03 -08002166 if (ddata->post_reset_quirk)
2167 ddata->post_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002168
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002169 error = sysc_wait_softreset(ddata);
2170 if (error)
2171 dev_warn(ddata->dev, "OCP softreset timed out\n");
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002172
Tony Lindgren4e23be42019-06-10 04:48:05 -07002173 if (ddata->reset_done_quirk)
2174 ddata->reset_done_quirk(ddata);
2175
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002176 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05302177}
2178
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002179/*
2180 * At this point the module is configured enough to read the revision but
2181 * module may not be completely configured yet to use PM runtime. Enable
2182 * all clocks directly during init to configure the quirks needed for PM
2183 * runtime based on the revision register.
2184 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08002185static int sysc_init_module(struct sysc *ddata)
2186{
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002187 bool rstctrl_deasserted = false;
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002188 int error = 0;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002189
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002190 error = sysc_clockdomain_init(ddata);
2191 if (error)
2192 return error;
2193
Tony Lindgrend0989132019-09-05 07:37:22 -07002194 sysc_clkdm_deny_idle(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002195
Tony Lindgrend0989132019-09-05 07:37:22 -07002196 /*
2197 * Always enable clocks. The bootloader may or may not have enabled
2198 * the related clocks.
2199 */
2200 error = sysc_enable_opt_clocks(ddata);
2201 if (error)
2202 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002203
Tony Lindgrend0989132019-09-05 07:37:22 -07002204 error = sysc_enable_main_clocks(ddata);
2205 if (error)
2206 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05302207
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002208 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
Tero Kristodf4f3452019-10-07 15:29:30 +03002209 error = reset_control_deassert(ddata->rsts);
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002210 if (error)
2211 goto err_main_clocks;
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002212 rstctrl_deasserted = true;
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002213 }
2214
Tony Lindgren566a9b052017-12-15 09:41:19 -08002215 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002216 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002217 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002218
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002219 if (ddata->legacy_mode) {
2220 error = sysc_legacy_init(ddata);
2221 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002222 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002223 }
2224
Tony Lindgrend0989132019-09-05 07:37:22 -07002225 if (!ddata->legacy_mode) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002226 error = sysc_enable_module(ddata->dev);
2227 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002228 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002229 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002230
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002231 error = sysc_reset(ddata);
2232 if (error)
2233 dev_err(ddata->dev, "Reset failed with %d\n", error);
2234
Tero Kristocdc56c12019-10-07 15:29:31 +03002235 if (error && !ddata->legacy_mode)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002236 sysc_disable_module(ddata->dev);
2237
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002238err_main_clocks:
Tero Kristocdc56c12019-10-07 15:29:31 +03002239 if (error)
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002240 sysc_disable_main_clocks(ddata);
2241err_opt_clocks:
Tony Lindgrend0989132019-09-05 07:37:22 -07002242 /* No re-enable of clockdomain autoidle to prevent module autoidle */
Tero Kristocdc56c12019-10-07 15:29:31 +03002243 if (error) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002244 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002245 sysc_clkdm_allow_idle(ddata);
2246 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002247
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002248 if (error && rstctrl_deasserted &&
2249 !(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
2250 reset_control_assert(ddata->rsts);
2251
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002252 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002253}
2254
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002255static int sysc_init_sysc_mask(struct sysc *ddata)
2256{
2257 struct device_node *np = ddata->dev->of_node;
2258 int error;
2259 u32 val;
2260
2261 error = of_property_read_u32(np, "ti,sysc-mask", &val);
2262 if (error)
2263 return 0;
2264
Tony Lindgrene212abd2019-07-22 03:44:52 -07002265 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002266
2267 return 0;
2268}
2269
2270static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
2271 const char *name)
2272{
2273 struct device_node *np = ddata->dev->of_node;
2274 struct property *prop;
2275 const __be32 *p;
2276 u32 val;
2277
2278 of_property_for_each_u32(np, name, prop, p, val) {
2279 if (val >= SYSC_NR_IDLEMODES) {
2280 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
2281 return -EINVAL;
2282 }
2283 *idlemodes |= (1 << val);
2284 }
2285
2286 return 0;
2287}
2288
2289static int sysc_init_idlemodes(struct sysc *ddata)
2290{
2291 int error;
2292
2293 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
2294 "ti,sysc-midle");
2295 if (error)
2296 return error;
2297
2298 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
2299 "ti,sysc-sidle");
2300 if (error)
2301 return error;
2302
2303 return 0;
2304}
2305
2306/*
2307 * Only some devices on omap4 and later have SYSCONFIG reset done
2308 * bit. We can detect this if there is no SYSSTATUS at all, or the
2309 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
2310 * have multiple bits for the child devices like OHCI and EHCI.
2311 * Depends on SYSC being parsed first.
2312 */
2313static int sysc_init_syss_mask(struct sysc *ddata)
2314{
2315 struct device_node *np = ddata->dev->of_node;
2316 int error;
2317 u32 val;
2318
2319 error = of_property_read_u32(np, "ti,syss-mask", &val);
2320 if (error) {
2321 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
2322 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
2323 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2324 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2325
2326 return 0;
2327 }
2328
2329 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2330 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2331
2332 ddata->cfg.syss_mask = val;
2333
2334 return 0;
2335}
2336
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002337/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002338 * Many child device drivers need to have fck and opt clocks available
2339 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002340 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002341static int sysc_child_add_named_clock(struct sysc *ddata,
2342 struct device *child,
2343 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002344{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002345 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002346 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002347 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002348
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002349 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002350 return 0;
2351
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002352 clk = clk_get(child, name);
2353 if (!IS_ERR(clk)) {
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002354 error = -EEXIST;
2355 goto put_clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002356 }
2357
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002358 clk = clk_get(ddata->dev, name);
2359 if (IS_ERR(clk))
2360 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002361
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002362 l = clkdev_create(clk, name, dev_name(child));
2363 if (!l)
2364 error = -ENOMEM;
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002365put_clk:
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002366 clk_put(clk);
2367
2368 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002369}
2370
Tony Lindgren09dfe582018-04-16 10:25:52 -07002371static int sysc_child_add_clocks(struct sysc *ddata,
2372 struct device *child)
2373{
2374 int i, error;
2375
2376 for (i = 0; i < ddata->nr_clocks; i++) {
2377 error = sysc_child_add_named_clock(ddata,
2378 child,
2379 ddata->clock_roles[i]);
2380 if (error && error != -EEXIST) {
2381 dev_err(ddata->dev, "could not add child clock %s: %i\n",
2382 ddata->clock_roles[i], error);
2383
2384 return error;
2385 }
2386 }
2387
2388 return 0;
2389}
2390
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002391static struct device_type sysc_device_type = {
2392};
2393
2394static struct sysc *sysc_child_to_parent(struct device *dev)
2395{
2396 struct device *parent = dev->parent;
2397
2398 if (!parent || parent->type != &sysc_device_type)
2399 return NULL;
2400
2401 return dev_get_drvdata(parent);
2402}
2403
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002404static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
2405{
2406 struct sysc *ddata;
2407 int error;
2408
2409 ddata = sysc_child_to_parent(dev);
2410
2411 error = pm_generic_runtime_suspend(dev);
2412 if (error)
2413 return error;
2414
2415 if (!ddata->enabled)
2416 return 0;
2417
2418 return sysc_runtime_suspend(ddata->dev);
2419}
2420
2421static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
2422{
2423 struct sysc *ddata;
2424 int error;
2425
2426 ddata = sysc_child_to_parent(dev);
2427
2428 if (!ddata->enabled) {
2429 error = sysc_runtime_resume(ddata->dev);
2430 if (error < 0)
2431 dev_err(ddata->dev,
2432 "%s error: %i\n", __func__, error);
2433 }
2434
2435 return pm_generic_runtime_resume(dev);
2436}
2437
2438#ifdef CONFIG_PM_SLEEP
2439static int sysc_child_suspend_noirq(struct device *dev)
2440{
2441 struct sysc *ddata;
2442 int error;
2443
2444 ddata = sysc_child_to_parent(dev);
2445
Tony Lindgrenef55f822018-04-16 10:27:15 -07002446 dev_dbg(ddata->dev, "%s %s\n", __func__,
2447 ddata->name ? ddata->name : "");
2448
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002449 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002450 if (error) {
2451 dev_err(dev, "%s error at %i: %i\n",
2452 __func__, __LINE__, error);
2453
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002454 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002455 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002456
2457 if (!pm_runtime_status_suspended(dev)) {
2458 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002459 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07002460 dev_dbg(dev, "%s busy at %i: %i\n",
2461 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002462
Tony Lindgren4f3530f2018-08-08 01:07:06 -07002463 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002464 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002465
2466 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002467 if (error) {
2468 dev_err(dev, "%s error at %i: %i\n",
2469 __func__, __LINE__, error);
2470
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002471 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002472 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002473
2474 ddata->child_needs_resume = true;
2475 }
2476
2477 return 0;
2478}
2479
2480static int sysc_child_resume_noirq(struct device *dev)
2481{
2482 struct sysc *ddata;
2483 int error;
2484
2485 ddata = sysc_child_to_parent(dev);
2486
Tony Lindgrenef55f822018-04-16 10:27:15 -07002487 dev_dbg(ddata->dev, "%s %s\n", __func__,
2488 ddata->name ? ddata->name : "");
2489
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002490 if (ddata->child_needs_resume) {
2491 ddata->child_needs_resume = false;
2492
2493 error = sysc_runtime_resume(ddata->dev);
2494 if (error)
2495 dev_err(ddata->dev,
2496 "%s runtime resume error: %i\n",
2497 __func__, error);
2498
2499 error = pm_generic_runtime_resume(dev);
2500 if (error)
2501 dev_err(ddata->dev,
2502 "%s generic runtime resume: %i\n",
2503 __func__, error);
2504 }
2505
2506 return pm_generic_resume_noirq(dev);
2507}
2508#endif
2509
Tony Lindgrenb7182b42019-03-21 11:00:21 -07002510static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002511 .ops = {
2512 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
2513 sysc_child_runtime_resume,
2514 NULL)
2515 USE_PLATFORM_PM_SLEEP_OPS
2516 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
2517 sysc_child_resume_noirq)
2518 }
2519};
2520
Tony Lindgren9d8813612021-09-21 12:42:25 +03002521/* Caller needs to take list_lock if ever used outside of cpu_pm */
2522static void sysc_reinit_modules(struct sysc_soc_info *soc)
2523{
2524 struct sysc_module *module;
2525 struct list_head *pos;
2526 struct sysc *ddata;
2527 int error = 0;
2528
2529 list_for_each(pos, &sysc_soc->restored_modules) {
2530 module = list_entry(pos, struct sysc_module, node);
2531 ddata = module->ddata;
2532 error = sysc_reinit_module(ddata, ddata->enabled);
2533 }
2534}
2535
2536/**
2537 * sysc_context_notifier - optionally reset and restore module after idle
2538 * @nb: notifier block
2539 * @cmd: unused
2540 * @v: unused
2541 *
2542 * Some interconnect target modules need to be restored, or reset and restored
2543 * on CPU_PM CPU_PM_CLUSTER_EXIT notifier. This is needed at least for am335x
2544 * OTG and GPMC target modules even if the modules are unused.
2545 */
2546static int sysc_context_notifier(struct notifier_block *nb, unsigned long cmd,
2547 void *v)
2548{
2549 struct sysc_soc_info *soc;
2550
2551 soc = container_of(nb, struct sysc_soc_info, nb);
2552
2553 switch (cmd) {
2554 case CPU_CLUSTER_PM_ENTER:
2555 break;
2556 case CPU_CLUSTER_PM_ENTER_FAILED: /* No need to restore context */
2557 break;
2558 case CPU_CLUSTER_PM_EXIT:
2559 sysc_reinit_modules(soc);
2560 break;
2561 }
2562
2563 return NOTIFY_OK;
2564}
2565
2566/**
2567 * sysc_add_restored - optionally add reset and restore quirk hanlling
2568 * @ddata: device data
2569 */
2570static void sysc_add_restored(struct sysc *ddata)
2571{
2572 struct sysc_module *restored_module;
2573
2574 restored_module = kzalloc(sizeof(*restored_module), GFP_KERNEL);
2575 if (!restored_module)
2576 return;
2577
2578 restored_module->ddata = ddata;
2579
2580 mutex_lock(&sysc_soc->list_lock);
2581
2582 list_add(&restored_module->node, &sysc_soc->restored_modules);
2583
2584 if (sysc_soc->nb.notifier_call)
2585 goto out_unlock;
2586
2587 sysc_soc->nb.notifier_call = sysc_context_notifier;
2588 cpu_pm_register_notifier(&sysc_soc->nb);
2589
2590out_unlock:
2591 mutex_unlock(&sysc_soc->list_lock);
2592}
2593
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002594/**
2595 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
2596 * @ddata: device driver data
2597 * @child: child device driver
2598 *
2599 * Allow idle for child devices as done with _od_runtime_suspend().
2600 * Otherwise many child devices will not idle because of the permanent
2601 * parent usecount set in pm_runtime_irq_safe().
2602 *
2603 * Note that the long term solution is to just modify the child device
2604 * drivers to not set pm_runtime_irq_safe() and then this can be just
2605 * dropped.
2606 */
2607static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
2608{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002609 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
2610 dev_pm_domain_set(child, &sysc_child_pm_domain);
2611}
2612
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002613static int sysc_notifier_call(struct notifier_block *nb,
2614 unsigned long event, void *device)
2615{
2616 struct device *dev = device;
2617 struct sysc *ddata;
2618 int error;
2619
2620 ddata = sysc_child_to_parent(dev);
2621 if (!ddata)
2622 return NOTIFY_DONE;
2623
2624 switch (event) {
2625 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07002626 error = sysc_child_add_clocks(ddata, dev);
2627 if (error)
2628 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002629 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002630 break;
2631 default:
2632 break;
2633 }
2634
2635 return NOTIFY_DONE;
2636}
2637
2638static struct notifier_block sysc_nb = {
2639 .notifier_call = sysc_notifier_call,
2640};
2641
Tony Lindgren566a9b052017-12-15 09:41:19 -08002642/* Device tree configured quirks */
2643struct sysc_dts_quirk {
2644 const char *name;
2645 u32 mask;
2646};
2647
2648static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2649 { .name = "ti,no-idle-on-init",
2650 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2651 { .name = "ti,no-reset-on-init",
2652 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002653 { .name = "ti,no-idle",
2654 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002655};
2656
Tony Lindgren4014c082018-12-10 14:11:26 -08002657static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2658 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002659{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002660 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002661 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002662
2663 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002664 const char *name = sysc_dts_quirks[i].name;
2665
2666 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002667 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002668 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002669
2670 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002671 if (is_child) {
2672 dev_warn(ddata->dev,
2673 "dts flag should be at module level for %s\n",
2674 name);
2675 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002676 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002677}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002678
Tony Lindgren4014c082018-12-10 14:11:26 -08002679static int sysc_init_dts_quirks(struct sysc *ddata)
2680{
2681 struct device_node *np = ddata->dev->of_node;
2682 int error;
2683 u32 val;
2684
2685 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2686
2687 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002688 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2689 if (!error) {
2690 if (val > 255) {
2691 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2692 val);
2693 }
2694
2695 ddata->cfg.srst_udelay = (u8)val;
2696 }
2697
2698 return 0;
2699}
2700
Tony Lindgren0eecc632017-10-10 14:23:43 -07002701static void sysc_unprepare(struct sysc *ddata)
2702{
2703 int i;
2704
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002705 if (!ddata->clocks)
2706 return;
2707
Tony Lindgren0eecc632017-10-10 14:23:43 -07002708 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2709 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2710 clk_unprepare(ddata->clocks[i]);
2711 }
2712}
2713
Tony Lindgren70a65242017-12-15 09:41:09 -08002714/*
2715 * Common sysc register bits found on omap2, also known as type1
2716 */
2717static const struct sysc_regbits sysc_regbits_omap2 = {
2718 .dmadisable_shift = -ENODEV,
2719 .midle_shift = 12,
2720 .sidle_shift = 3,
2721 .clkact_shift = 8,
2722 .emufree_shift = 5,
2723 .enwkup_shift = 2,
2724 .srst_shift = 1,
2725 .autoidle_shift = 0,
2726};
2727
2728static const struct sysc_capabilities sysc_omap2 = {
2729 .type = TI_SYSC_OMAP2,
2730 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2731 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2732 SYSC_OMAP2_AUTOIDLE,
2733 .regbits = &sysc_regbits_omap2,
2734};
2735
2736/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2737static const struct sysc_capabilities sysc_omap2_timer = {
2738 .type = TI_SYSC_OMAP2_TIMER,
2739 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2740 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2741 SYSC_OMAP2_AUTOIDLE,
2742 .regbits = &sysc_regbits_omap2,
2743 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2744};
2745
2746/*
2747 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2748 * with different sidle position
2749 */
2750static const struct sysc_regbits sysc_regbits_omap3_sham = {
2751 .dmadisable_shift = -ENODEV,
2752 .midle_shift = -ENODEV,
2753 .sidle_shift = 4,
2754 .clkact_shift = -ENODEV,
2755 .enwkup_shift = -ENODEV,
2756 .srst_shift = 1,
2757 .autoidle_shift = 0,
2758 .emufree_shift = -ENODEV,
2759};
2760
2761static const struct sysc_capabilities sysc_omap3_sham = {
2762 .type = TI_SYSC_OMAP3_SHAM,
2763 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2764 .regbits = &sysc_regbits_omap3_sham,
2765};
2766
2767/*
2768 * AES register bits found on omap3 and later, a variant of
2769 * sysc_regbits_omap2 with different sidle position
2770 */
2771static const struct sysc_regbits sysc_regbits_omap3_aes = {
2772 .dmadisable_shift = -ENODEV,
2773 .midle_shift = -ENODEV,
2774 .sidle_shift = 6,
2775 .clkact_shift = -ENODEV,
2776 .enwkup_shift = -ENODEV,
2777 .srst_shift = 1,
2778 .autoidle_shift = 0,
2779 .emufree_shift = -ENODEV,
2780};
2781
2782static const struct sysc_capabilities sysc_omap3_aes = {
2783 .type = TI_SYSC_OMAP3_AES,
2784 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2785 .regbits = &sysc_regbits_omap3_aes,
2786};
2787
2788/*
2789 * Common sysc register bits found on omap4, also known as type2
2790 */
2791static const struct sysc_regbits sysc_regbits_omap4 = {
2792 .dmadisable_shift = 16,
2793 .midle_shift = 4,
2794 .sidle_shift = 2,
2795 .clkact_shift = -ENODEV,
2796 .enwkup_shift = -ENODEV,
2797 .emufree_shift = 1,
2798 .srst_shift = 0,
2799 .autoidle_shift = -ENODEV,
2800};
2801
2802static const struct sysc_capabilities sysc_omap4 = {
2803 .type = TI_SYSC_OMAP4,
2804 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2805 SYSC_OMAP4_SOFTRESET,
2806 .regbits = &sysc_regbits_omap4,
2807};
2808
2809static const struct sysc_capabilities sysc_omap4_timer = {
2810 .type = TI_SYSC_OMAP4_TIMER,
2811 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2812 SYSC_OMAP4_SOFTRESET,
2813 .regbits = &sysc_regbits_omap4,
2814};
2815
2816/*
2817 * Common sysc register bits found on omap4, also known as type3
2818 */
2819static const struct sysc_regbits sysc_regbits_omap4_simple = {
2820 .dmadisable_shift = -ENODEV,
2821 .midle_shift = 2,
2822 .sidle_shift = 0,
2823 .clkact_shift = -ENODEV,
2824 .enwkup_shift = -ENODEV,
2825 .srst_shift = -ENODEV,
2826 .emufree_shift = -ENODEV,
2827 .autoidle_shift = -ENODEV,
2828};
2829
2830static const struct sysc_capabilities sysc_omap4_simple = {
2831 .type = TI_SYSC_OMAP4_SIMPLE,
2832 .regbits = &sysc_regbits_omap4_simple,
2833};
2834
2835/*
2836 * SmartReflex sysc found on omap34xx
2837 */
2838static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2839 .dmadisable_shift = -ENODEV,
2840 .midle_shift = -ENODEV,
2841 .sidle_shift = -ENODEV,
2842 .clkact_shift = 20,
2843 .enwkup_shift = -ENODEV,
2844 .srst_shift = -ENODEV,
2845 .emufree_shift = -ENODEV,
2846 .autoidle_shift = -ENODEV,
2847};
2848
2849static const struct sysc_capabilities sysc_34xx_sr = {
2850 .type = TI_SYSC_OMAP34XX_SR,
2851 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2852 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002853 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2854 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002855};
2856
2857/*
2858 * SmartReflex sysc found on omap36xx and later
2859 */
2860static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2861 .dmadisable_shift = -ENODEV,
2862 .midle_shift = -ENODEV,
2863 .sidle_shift = 24,
2864 .clkact_shift = -ENODEV,
2865 .enwkup_shift = 26,
2866 .srst_shift = -ENODEV,
2867 .emufree_shift = -ENODEV,
2868 .autoidle_shift = -ENODEV,
2869};
2870
2871static const struct sysc_capabilities sysc_36xx_sr = {
2872 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002873 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002874 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002875 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002876};
2877
2878static const struct sysc_capabilities sysc_omap4_sr = {
2879 .type = TI_SYSC_OMAP4_SR,
2880 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002881 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002882};
2883
2884/*
2885 * McASP register bits found on omap4 and later
2886 */
2887static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2888 .dmadisable_shift = -ENODEV,
2889 .midle_shift = -ENODEV,
2890 .sidle_shift = 0,
2891 .clkact_shift = -ENODEV,
2892 .enwkup_shift = -ENODEV,
2893 .srst_shift = -ENODEV,
2894 .emufree_shift = -ENODEV,
2895 .autoidle_shift = -ENODEV,
2896};
2897
2898static const struct sysc_capabilities sysc_omap4_mcasp = {
2899 .type = TI_SYSC_OMAP4_MCASP,
2900 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002901 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2902};
2903
2904/*
2905 * McASP found on dra7 and later
2906 */
2907static const struct sysc_capabilities sysc_dra7_mcasp = {
2908 .type = TI_SYSC_OMAP4_SIMPLE,
2909 .regbits = &sysc_regbits_omap4_simple,
2910 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002911};
2912
2913/*
2914 * FS USB host found on omap4 and later
2915 */
2916static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2917 .dmadisable_shift = -ENODEV,
2918 .midle_shift = -ENODEV,
2919 .sidle_shift = 24,
2920 .clkact_shift = -ENODEV,
2921 .enwkup_shift = 26,
2922 .srst_shift = -ENODEV,
2923 .emufree_shift = -ENODEV,
2924 .autoidle_shift = -ENODEV,
2925};
2926
2927static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2928 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2929 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2930 .regbits = &sysc_regbits_omap4_usb_host_fs,
2931};
2932
Faiz Abbas7f35e632018-07-09 22:18:38 +05302933static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2934 .dmadisable_shift = -ENODEV,
2935 .midle_shift = -ENODEV,
2936 .sidle_shift = -ENODEV,
2937 .clkact_shift = -ENODEV,
2938 .enwkup_shift = 4,
2939 .srst_shift = 0,
2940 .emufree_shift = -ENODEV,
2941 .autoidle_shift = -ENODEV,
2942};
2943
2944static const struct sysc_capabilities sysc_dra7_mcan = {
2945 .type = TI_SYSC_DRA7_MCAN,
2946 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2947 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002948 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302949};
2950
Suman Annab2745d92020-02-27 16:28:34 -06002951/*
2952 * PRUSS found on some AM33xx, AM437x and AM57xx SoCs
2953 */
2954static const struct sysc_capabilities sysc_pruss = {
2955 .type = TI_SYSC_PRUSS,
2956 .sysc_mask = SYSC_PRUSS_STANDBY_INIT | SYSC_PRUSS_SUB_MWAIT,
2957 .regbits = &sysc_regbits_omap4_simple,
2958 .mod_quirks = SYSC_MODULE_QUIRK_PRUSS,
2959};
2960
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002961static int sysc_init_pdata(struct sysc *ddata)
2962{
2963 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002964 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002965
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002966 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002967 return 0;
2968
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002969 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2970 if (!mdata)
2971 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002972
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002973 if (ddata->legacy_mode) {
2974 mdata->name = ddata->legacy_mode;
2975 mdata->module_pa = ddata->module_pa;
2976 mdata->module_size = ddata->module_size;
2977 mdata->offsets = ddata->offsets;
2978 mdata->nr_offsets = SYSC_MAX_REGS;
2979 mdata->cap = ddata->cap;
2980 mdata->cfg = &ddata->cfg;
2981 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002982
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002983 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002984
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002985 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002986}
2987
Tony Lindgren70a65242017-12-15 09:41:09 -08002988static int sysc_init_match(struct sysc *ddata)
2989{
2990 const struct sysc_capabilities *cap;
2991
2992 cap = of_device_get_match_data(ddata->dev);
2993 if (!cap)
2994 return -EINVAL;
2995
2996 ddata->cap = cap;
2997 if (ddata->cap)
2998 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2999
3000 return 0;
3001}
3002
Tony Lindgren76f0f772018-02-23 08:28:45 -08003003static void ti_sysc_idle(struct work_struct *work)
3004{
3005 struct sysc *ddata;
3006
3007 ddata = container_of(work, struct sysc, idle_work.work);
3008
Tony Lindgrend0989132019-09-05 07:37:22 -07003009 /*
3010 * One time decrement of clock usage counts if left on from init.
3011 * Note that we disable opt clocks unconditionally in this case
3012 * as they are enabled unconditionally during init without
3013 * considering sysc_opt_clks_needed() at that point.
3014 */
3015 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
3016 SYSC_QUIRK_NO_IDLE_ON_INIT)) {
Tony Lindgrend0989132019-09-05 07:37:22 -07003017 sysc_disable_main_clocks(ddata);
3018 sysc_disable_opt_clocks(ddata);
3019 sysc_clkdm_allow_idle(ddata);
3020 }
3021
3022 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
3023 if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE)
3024 return;
3025
3026 /*
3027 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
3028 * and SYSC_QUIRK_NO_RESET_ON_INIT
3029 */
Tony Lindgren76f0f772018-02-23 08:28:45 -08003030 if (pm_runtime_active(ddata->dev))
3031 pm_runtime_put_sync(ddata->dev);
3032}
3033
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003034/*
3035 * SoC model and features detection. Only needed for SoCs that need
3036 * special handling for quirks, no need to list others.
3037 */
3038static const struct soc_device_attribute sysc_soc_match[] = {
3039 SOC_FLAG("OMAP242*", SOC_2420),
3040 SOC_FLAG("OMAP243*", SOC_2430),
3041 SOC_FLAG("OMAP3[45]*", SOC_3430),
3042 SOC_FLAG("OMAP3[67]*", SOC_3630),
3043 SOC_FLAG("OMAP443*", SOC_4430),
3044 SOC_FLAG("OMAP446*", SOC_4460),
3045 SOC_FLAG("OMAP447*", SOC_4470),
3046 SOC_FLAG("OMAP54*", SOC_5430),
3047 SOC_FLAG("AM433", SOC_AM3),
3048 SOC_FLAG("AM43*", SOC_AM4),
3049 SOC_FLAG("DRA7*", SOC_DRA7),
3050
3051 { /* sentinel */ },
3052};
3053
3054/*
3055 * List of SoCs variants with disabled features. By default we assume all
3056 * devices in the device tree are available so no need to list those SoCs.
3057 */
3058static const struct soc_device_attribute sysc_soc_feat_match[] = {
3059 /* OMAP3430/3530 and AM3517 variants with some accelerators disabled */
3060 SOC_FLAG("AM3505", DIS_SGX),
3061 SOC_FLAG("OMAP3525", DIS_SGX),
3062 SOC_FLAG("OMAP3515", DIS_IVA | DIS_SGX),
3063 SOC_FLAG("OMAP3503", DIS_ISP | DIS_IVA | DIS_SGX),
3064
3065 /* OMAP3630/DM3730 variants with some accelerators disabled */
3066 SOC_FLAG("AM3703", DIS_IVA | DIS_SGX),
3067 SOC_FLAG("DM3725", DIS_SGX),
3068 SOC_FLAG("OMAP3611", DIS_ISP | DIS_IVA | DIS_SGX),
3069 SOC_FLAG("OMAP3615/AM3715", DIS_IVA),
3070 SOC_FLAG("OMAP3621", DIS_ISP),
3071
3072 { /* sentinel */ },
3073};
3074
3075static int sysc_add_disabled(unsigned long base)
3076{
3077 struct sysc_address *disabled_module;
3078
3079 disabled_module = kzalloc(sizeof(*disabled_module), GFP_KERNEL);
3080 if (!disabled_module)
3081 return -ENOMEM;
3082
3083 disabled_module->base = base;
3084
3085 mutex_lock(&sysc_soc->list_lock);
3086 list_add(&disabled_module->node, &sysc_soc->disabled_modules);
3087 mutex_unlock(&sysc_soc->list_lock);
3088
3089 return 0;
3090}
3091
3092/*
Tony Lindgren9d8813612021-09-21 12:42:25 +03003093 * One time init to detect the booted SoC, disable unavailable features
3094 * and initialize list for optional cpu_pm notifier.
3095 *
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003096 * Note that we initialize static data shared across all ti-sysc instances
3097 * so ddata is only used for SoC type. This can be called from module_init
3098 * once we no longer need to rely on platform data.
3099 */
Tony Lindgren9d8813612021-09-21 12:42:25 +03003100static int sysc_init_static_data(struct sysc *ddata)
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003101{
3102 const struct soc_device_attribute *match;
3103 struct ti_sysc_platform_data *pdata;
3104 unsigned long features = 0;
Tony Lindgren5f7259a2021-03-08 11:35:09 +02003105 struct device_node *np;
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003106
3107 if (sysc_soc)
3108 return 0;
3109
3110 sysc_soc = kzalloc(sizeof(*sysc_soc), GFP_KERNEL);
3111 if (!sysc_soc)
3112 return -ENOMEM;
3113
3114 mutex_init(&sysc_soc->list_lock);
3115 INIT_LIST_HEAD(&sysc_soc->disabled_modules);
Tony Lindgren9d8813612021-09-21 12:42:25 +03003116 INIT_LIST_HEAD(&sysc_soc->restored_modules);
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003117 sysc_soc->general_purpose = true;
3118
3119 pdata = dev_get_platdata(ddata->dev);
3120 if (pdata && pdata->soc_type_gp)
3121 sysc_soc->general_purpose = pdata->soc_type_gp();
3122
3123 match = soc_device_match(sysc_soc_match);
3124 if (match && match->data)
3125 sysc_soc->soc = (int)match->data;
3126
Tony Lindgren5f7259a2021-03-08 11:35:09 +02003127 /*
3128 * Check and warn about possible old incomplete dtb. We now want to see
3129 * simple-pm-bus instead of simple-bus in the dtb for genpd using SoCs.
3130 */
3131 switch (sysc_soc->soc) {
3132 case SOC_AM3:
3133 case SOC_AM4:
Tony Lindgren4adcf4c2021-03-12 10:23:48 +02003134 case SOC_4430 ... SOC_4470:
3135 case SOC_5430:
3136 case SOC_DRA7:
Tony Lindgren5f7259a2021-03-08 11:35:09 +02003137 np = of_find_node_by_path("/ocp");
3138 WARN_ONCE(np && of_device_is_compatible(np, "simple-bus"),
3139 "ti-sysc: Incomplete old dtb, please update\n");
3140 break;
3141 default:
3142 break;
3143 }
3144
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07003145 /* Ignore devices that are not available on HS and EMU SoCs */
3146 if (!sysc_soc->general_purpose) {
3147 switch (sysc_soc->soc) {
3148 case SOC_3430 ... SOC_3630:
3149 sysc_add_disabled(0x48304000); /* timer12 */
3150 break;
Kevin Hilmana6d90e92021-07-20 11:27:16 -07003151 case SOC_AM3:
3152 sysc_add_disabled(0x48310000); /* rng */
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07003153 default:
3154 break;
Yang Li52fbb5a2021-02-02 15:00:05 +08003155 }
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07003156 }
3157
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003158 match = soc_device_match(sysc_soc_feat_match);
3159 if (!match)
3160 return 0;
3161
3162 if (match->data)
3163 features = (unsigned long)match->data;
3164
3165 /*
3166 * Add disabled devices to the list based on the module base.
3167 * Note that this must be done before we attempt to access the
3168 * device and have module revision checks working.
3169 */
3170 if (features & DIS_ISP)
3171 sysc_add_disabled(0x480bd400);
3172 if (features & DIS_IVA)
3173 sysc_add_disabled(0x5d000000);
3174 if (features & DIS_SGX)
3175 sysc_add_disabled(0x50000000);
3176
3177 return 0;
3178}
3179
Tony Lindgren9d8813612021-09-21 12:42:25 +03003180static void sysc_cleanup_static_data(void)
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003181{
Tony Lindgren9d8813612021-09-21 12:42:25 +03003182 struct sysc_module *restored_module;
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003183 struct sysc_address *disabled_module;
3184 struct list_head *pos, *tmp;
3185
3186 if (!sysc_soc)
3187 return;
3188
Tony Lindgren9d8813612021-09-21 12:42:25 +03003189 if (sysc_soc->nb.notifier_call)
3190 cpu_pm_unregister_notifier(&sysc_soc->nb);
3191
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003192 mutex_lock(&sysc_soc->list_lock);
Tony Lindgren9d8813612021-09-21 12:42:25 +03003193 list_for_each_safe(pos, tmp, &sysc_soc->restored_modules) {
3194 restored_module = list_entry(pos, struct sysc_module, node);
3195 list_del(pos);
3196 kfree(restored_module);
3197 }
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003198 list_for_each_safe(pos, tmp, &sysc_soc->disabled_modules) {
3199 disabled_module = list_entry(pos, struct sysc_address, node);
3200 list_del(pos);
3201 kfree(disabled_module);
3202 }
3203 mutex_unlock(&sysc_soc->list_lock);
3204}
3205
3206static int sysc_check_disabled_devices(struct sysc *ddata)
3207{
3208 struct sysc_address *disabled_module;
3209 struct list_head *pos;
3210 int error = 0;
3211
3212 mutex_lock(&sysc_soc->list_lock);
3213 list_for_each(pos, &sysc_soc->disabled_modules) {
3214 disabled_module = list_entry(pos, struct sysc_address, node);
3215 if (ddata->module_pa == disabled_module->base) {
3216 dev_dbg(ddata->dev, "module disabled for this SoC\n");
3217 error = -ENODEV;
3218 break;
3219 }
3220 }
3221 mutex_unlock(&sysc_soc->list_lock);
3222
3223 return error;
3224}
3225
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003226/*
3227 * Ignore timers tagged with no-reset and no-idle. These are likely in use,
3228 * for example by drivers/clocksource/timer-ti-dm-systimer.c. If more checks
3229 * are needed, we could also look at the timer register configuration.
3230 */
3231static int sysc_check_active_timer(struct sysc *ddata)
3232{
3233 if (ddata->cap->type != TI_SYSC_OMAP2_TIMER &&
3234 ddata->cap->type != TI_SYSC_OMAP4_TIMER)
3235 return 0;
3236
3237 if ((ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) &&
3238 (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE))
Grygorii Strashko65fb7362020-11-18 16:19:00 +02003239 return -ENXIO;
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003240
3241 return 0;
3242}
3243
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07003244static const struct of_device_id sysc_match_table[] = {
3245 { .compatible = "simple-bus", },
3246 { /* sentinel */ },
3247};
3248
Tony Lindgren0eecc632017-10-10 14:23:43 -07003249static int sysc_probe(struct platform_device *pdev)
3250{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003251 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003252 struct sysc *ddata;
3253 int error;
3254
3255 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
3256 if (!ddata)
3257 return -ENOMEM;
3258
Tony Lindgren29281352020-11-16 12:57:13 +02003259 ddata->offsets[SYSC_REVISION] = -ENODEV;
3260 ddata->offsets[SYSC_SYSCONFIG] = -ENODEV;
3261 ddata->offsets[SYSC_SYSSTATUS] = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003262 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003263 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003264
Tony Lindgren9d8813612021-09-21 12:42:25 +03003265 error = sysc_init_static_data(ddata);
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003266 if (error)
3267 return error;
3268
Tony Lindgren70a65242017-12-15 09:41:09 -08003269 error = sysc_init_match(ddata);
3270 if (error)
3271 return error;
3272
Tony Lindgren566a9b052017-12-15 09:41:19 -08003273 error = sysc_init_dts_quirks(ddata);
3274 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003275 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003276
Tony Lindgren0eecc632017-10-10 14:23:43 -07003277 error = sysc_map_and_check_registers(ddata);
3278 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003279 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003280
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003281 error = sysc_init_sysc_mask(ddata);
3282 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003283 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003284
3285 error = sysc_init_idlemodes(ddata);
3286 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003287 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003288
3289 error = sysc_init_syss_mask(ddata);
3290 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003291 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003292
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003293 error = sysc_init_pdata(ddata);
3294 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003295 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003296
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003297 sysc_init_early_quirks(ddata);
3298
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003299 error = sysc_check_disabled_devices(ddata);
3300 if (error)
3301 return error;
3302
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003303 error = sysc_check_active_timer(ddata);
Tony Lindgren06a089e2021-08-11 08:34:46 +03003304 if (error == -ENXIO)
Tony Lindgren3ff340e2021-06-11 08:42:50 +03003305 ddata->reserved = true;
Tony Lindgren06a089e2021-08-11 08:34:46 +03003306 else if (error)
3307 return error;
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003308
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003309 error = sysc_get_clocks(ddata);
3310 if (error)
3311 return error;
3312
Tony Lindgren50622362018-04-16 10:20:27 -07003313 error = sysc_init_resets(ddata);
3314 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003315 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003316
3317 error = sysc_init_module(ddata);
3318 if (error)
3319 goto unprepare;
3320
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07003321 pm_runtime_enable(ddata->dev);
Zhang Qilongcea08162021-05-31 22:25:42 +08003322 error = pm_runtime_resume_and_get(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003323 if (error < 0) {
Tony Lindgren0eecc632017-10-10 14:23:43 -07003324 pm_runtime_disable(ddata->dev);
3325 goto unprepare;
3326 }
3327
Tero Kristocdc56c12019-10-07 15:29:31 +03003328 /* Balance use counts as PM runtime should have enabled these all */
Tero Kristocdc56c12019-10-07 15:29:31 +03003329 if (!(ddata->cfg.quirks &
3330 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))) {
3331 sysc_disable_main_clocks(ddata);
3332 sysc_disable_opt_clocks(ddata);
3333 sysc_clkdm_allow_idle(ddata);
3334 }
3335
Tony Lindgren4097c9a2020-11-16 12:57:13 +02003336 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
3337 reset_control_assert(ddata->rsts);
3338
Tony Lindgren0eecc632017-10-10 14:23:43 -07003339 sysc_show_registers(ddata);
3340
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003341 ddata->dev->type = &sysc_device_type;
Tony Lindgren3ff340e2021-06-11 08:42:50 +03003342
3343 if (!ddata->reserved) {
3344 error = of_platform_populate(ddata->dev->of_node,
3345 sysc_match_table,
3346 pdata ? pdata->auxdata : NULL,
3347 ddata->dev);
3348 if (error)
3349 goto err;
3350 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07003351
Tony Lindgren76f0f772018-02-23 08:28:45 -08003352 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
3353
3354 /* At least earlycon won't survive without deferred idle */
Tony Lindgrend0989132019-09-05 07:37:22 -07003355 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
3356 SYSC_QUIRK_NO_IDLE_ON_INIT |
Tony Lindgren76f0f772018-02-23 08:28:45 -08003357 SYSC_QUIRK_NO_RESET_ON_INIT)) {
3358 schedule_delayed_work(&ddata->idle_work, 3000);
3359 } else {
3360 pm_runtime_put(&pdev->dev);
3361 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07003362
Tony Lindgren9d8813612021-09-21 12:42:25 +03003363 if (ddata->cfg.quirks & SYSC_QUIRK_REINIT_ON_CTX_LOST)
3364 sysc_add_restored(ddata);
3365
Tony Lindgren0eecc632017-10-10 14:23:43 -07003366 return 0;
3367
3368err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07003369 pm_runtime_put_sync(&pdev->dev);
3370 pm_runtime_disable(&pdev->dev);
3371unprepare:
3372 sysc_unprepare(ddata);
3373
3374 return error;
3375}
3376
Tony Lindgren684be5a2017-10-13 10:48:40 -07003377static int sysc_remove(struct platform_device *pdev)
3378{
3379 struct sysc *ddata = platform_get_drvdata(pdev);
3380 int error;
3381
Tony Lindgren76f0f772018-02-23 08:28:45 -08003382 cancel_delayed_work_sync(&ddata->idle_work);
3383
Zhang Qilongcea08162021-05-31 22:25:42 +08003384 error = pm_runtime_resume_and_get(ddata->dev);
Tony Lindgren684be5a2017-10-13 10:48:40 -07003385 if (error < 0) {
Tony Lindgren684be5a2017-10-13 10:48:40 -07003386 pm_runtime_disable(ddata->dev);
3387 goto unprepare;
3388 }
3389
3390 of_platform_depopulate(&pdev->dev);
3391
Tony Lindgren684be5a2017-10-13 10:48:40 -07003392 pm_runtime_put_sync(&pdev->dev);
3393 pm_runtime_disable(&pdev->dev);
Tony Lindgrena7b5d7c2021-02-18 13:06:57 +02003394
3395 if (!reset_control_status(ddata->rsts))
3396 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07003397
3398unprepare:
3399 sysc_unprepare(ddata);
3400
3401 return 0;
3402}
3403
Tony Lindgren0eecc632017-10-10 14:23:43 -07003404static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08003405 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
3406 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
3407 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
3408 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
3409 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
3410 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
3411 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
3412 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
3413 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
3414 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
3415 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08003416 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08003417 { .compatible = "ti,sysc-usb-host-fs",
3418 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05303419 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Suman Annab2745d92020-02-27 16:28:34 -06003420 { .compatible = "ti,sysc-pruss", .data = &sysc_pruss, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07003421 { },
3422};
3423MODULE_DEVICE_TABLE(of, sysc_match);
3424
3425static struct platform_driver sysc_driver = {
3426 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07003427 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07003428 .driver = {
3429 .name = "ti-sysc",
3430 .of_match_table = sysc_match,
3431 .pm = &sysc_pm_ops,
3432 },
3433};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003434
3435static int __init sysc_init(void)
3436{
3437 bus_register_notifier(&platform_bus_type, &sysc_nb);
3438
3439 return platform_driver_register(&sysc_driver);
3440}
3441module_init(sysc_init);
3442
3443static void __exit sysc_exit(void)
3444{
3445 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
3446 platform_driver_unregister(&sysc_driver);
Tony Lindgren9d8813612021-09-21 12:42:25 +03003447 sysc_cleanup_static_data();
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003448}
3449module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003450
3451MODULE_DESCRIPTION("TI sysc interconnect target driver");
3452MODULE_LICENSE("GPL v2");