blob: efd8f0f7cfe34b0b81348e0ae4c91baa9ce06d19 [file] [log] [blame]
Suman Anna54d66222019-08-13 04:13:32 -07001// SPDX-License-Identifier: GPL-2.0
Tony Lindgren0eecc632017-10-10 14:23:43 -07002/*
3 * ti-sysc.c - Texas Instruments sysc interconnect target driver
Tony Lindgren0eecc632017-10-10 14:23:43 -07004 */
5
6#include <linux/io.h>
7#include <linux/clk.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -08008#include <linux/clkdev.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -08009#include <linux/delay.h>
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080010#include <linux/list.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070011#include <linux/module.h>
12#include <linux/platform_device.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080013#include <linux/pm_domain.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070014#include <linux/pm_runtime.h>
Tony Lindgren50622362018-04-16 10:20:27 -070015#include <linux/reset.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070016#include <linux/of_address.h>
17#include <linux/of_platform.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080018#include <linux/slab.h>
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080019#include <linux/sys_soc.h>
Tony Lindgrenb3e94312021-09-21 12:42:25 +030020#include <linux/timekeeping.h>
Faiz Abbas596e7952018-07-09 22:18:39 +053021#include <linux/iopoll.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080022
Tony Lindgren70a65242017-12-15 09:41:09 -080023#include <linux/platform_data/ti-sysc.h>
24
25#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070026
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080027#define DIS_ISP BIT(2)
28#define DIS_IVA BIT(1)
29#define DIS_SGX BIT(0)
30
31#define SOC_FLAG(match, flag) { .machine = match, .data = (void *)(flag), }
32
Tony Lindgrene4a8fc02020-06-10 15:31:54 -070033#define MAX_MODULE_SOFTRESET_WAIT 10000
Faiz Abbas596e7952018-07-09 22:18:39 +053034
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080035enum sysc_soc {
36 SOC_UNKNOWN,
37 SOC_2420,
38 SOC_2430,
39 SOC_3430,
40 SOC_3630,
41 SOC_4430,
42 SOC_4460,
43 SOC_4470,
44 SOC_5430,
45 SOC_AM3,
46 SOC_AM4,
47 SOC_DRA7,
48};
49
50struct sysc_address {
51 unsigned long base;
52 struct list_head node;
53};
54
55struct sysc_soc_info {
56 unsigned long general_purpose:1;
57 enum sysc_soc soc;
58 struct mutex list_lock; /* disabled modules list lock */
59 struct list_head disabled_modules;
60};
Tony Lindgren0eecc632017-10-10 14:23:43 -070061
62enum sysc_clocks {
63 SYSC_FCK,
64 SYSC_ICK,
Tony Lindgren09dfe582018-04-16 10:25:52 -070065 SYSC_OPTFCK0,
66 SYSC_OPTFCK1,
67 SYSC_OPTFCK2,
68 SYSC_OPTFCK3,
69 SYSC_OPTFCK4,
70 SYSC_OPTFCK5,
71 SYSC_OPTFCK6,
72 SYSC_OPTFCK7,
Tony Lindgren0eecc632017-10-10 14:23:43 -070073 SYSC_MAX_CLOCKS,
74};
75
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080076static struct sysc_soc_info *sysc_soc;
77static const char * const reg_names[] = { "rev", "sysc", "syss", };
Tony Lindgrena54275f2019-03-21 11:00:21 -070078static const char * const clock_names[SYSC_MAX_CLOCKS] = {
79 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
80 "opt5", "opt6", "opt7",
81};
Tony Lindgren0eecc632017-10-10 14:23:43 -070082
Tony Lindgrenc5a2de92017-12-15 09:41:23 -080083#define SYSC_IDLEMODE_MASK 3
84#define SYSC_CLOCKACTIVITY_MASK 3
85
Tony Lindgren0eecc632017-10-10 14:23:43 -070086/**
87 * struct sysc - TI sysc interconnect target module registers and capabilities
88 * @dev: struct device pointer
89 * @module_pa: physical address of the interconnect target module
90 * @module_size: size of the interconnect target module
91 * @module_va: virtual address of the interconnect target module
92 * @offsets: register offsets from module base
Suman Annab58056d2019-08-13 04:13:32 -070093 * @mdata: ti-sysc to hwmod translation data for a module
Tony Lindgren0eecc632017-10-10 14:23:43 -070094 * @clocks: clocks used by the interconnect target module
Tony Lindgren09dfe582018-04-16 10:25:52 -070095 * @clock_roles: clock role names for the found clocks
96 * @nr_clocks: number of clocks used by the interconnect target module
Suman Annab58056d2019-08-13 04:13:32 -070097 * @rsts: resets used by the interconnect target module
Tony Lindgren0eecc632017-10-10 14:23:43 -070098 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -080099 * @cap: interconnect target module capabilities
100 * @cfg: interconnect target module configuration
Suman Annab58056d2019-08-13 04:13:32 -0700101 * @cookie: data used by legacy platform callbacks
Tony Lindgren566a9b052017-12-15 09:41:19 -0800102 * @name: name if available
103 * @revision: interconnect target module revision
Tony Lindgren3ff340e2021-06-11 08:42:50 +0300104 * @reserved: target module is reserved and already in use
Suman Annab58056d2019-08-13 04:13:32 -0700105 * @enabled: sysc runtime enabled status
Tony Lindgren62020f22018-02-22 13:59:44 -0800106 * @needs_resume: runtime resume needed on resume from suspend
Suman Annab58056d2019-08-13 04:13:32 -0700107 * @child_needs_resume: runtime resume needed for child on resume from suspend
108 * @disable_on_idle: status flag used for disabling modules with resets
109 * @idle_work: work structure used to perform delayed idle on a module
Tony Lindgrene64c0212020-02-24 12:58:03 -0800110 * @pre_reset_quirk: module specific pre-reset quirk
111 * @post_reset_quirk: module specific post-reset quirk
Tony Lindgren4e23be42019-06-10 04:48:05 -0700112 * @reset_done_quirk: module specific reset done quirk
Tony Lindgrend7f563d2019-08-14 05:18:16 -0700113 * @module_enable_quirk: module specific enable quirk
Tony Lindgrenc7d86692019-10-17 11:21:44 -0700114 * @module_disable_quirk: module specific disable quirk
Tony Lindgrene8639e12020-02-24 12:58:03 -0800115 * @module_unlock_quirk: module specific sysconfig unlock quirk
116 * @module_lock_quirk: module specific sysconfig lock quirk
Tony Lindgren0eecc632017-10-10 14:23:43 -0700117 */
118struct sysc {
119 struct device *dev;
120 u64 module_pa;
121 u32 module_size;
122 void __iomem *module_va;
123 int offsets[SYSC_MAX_REGS];
Tony Lindgrena3e92e72019-03-21 11:00:21 -0700124 struct ti_sysc_module_data *mdata;
Tony Lindgren09dfe582018-04-16 10:25:52 -0700125 struct clk **clocks;
126 const char **clock_roles;
127 int nr_clocks;
Tony Lindgren50622362018-04-16 10:20:27 -0700128 struct reset_control *rsts;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700129 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -0800130 const struct sysc_capabilities *cap;
131 struct sysc_config cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800132 struct ti_sysc_cookie cookie;
Tony Lindgren566a9b052017-12-15 09:41:19 -0800133 const char *name;
134 u32 revision;
Tony Lindgren3ff340e2021-06-11 08:42:50 +0300135 unsigned int reserved:1;
Tony Lindgren8383e252019-05-27 04:51:56 -0700136 unsigned int enabled:1;
137 unsigned int needs_resume:1;
138 unsigned int child_needs_resume:1;
Tony Lindgren76f0f772018-02-23 08:28:45 -0800139 struct delayed_work idle_work;
Tony Lindgrene64c0212020-02-24 12:58:03 -0800140 void (*pre_reset_quirk)(struct sysc *sysc);
141 void (*post_reset_quirk)(struct sysc *sysc);
Tony Lindgren4e23be42019-06-10 04:48:05 -0700142 void (*reset_done_quirk)(struct sysc *sysc);
Tony Lindgrend7f563d2019-08-14 05:18:16 -0700143 void (*module_enable_quirk)(struct sysc *sysc);
Tony Lindgrenc7d86692019-10-17 11:21:44 -0700144 void (*module_disable_quirk)(struct sysc *sysc);
Tony Lindgrene8639e12020-02-24 12:58:03 -0800145 void (*module_unlock_quirk)(struct sysc *sysc);
146 void (*module_lock_quirk)(struct sysc *sysc);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700147};
148
Tony Lindgren4014c082018-12-10 14:11:26 -0800149static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
150 bool is_child);
151
Tony Lindgrenb7182b42019-03-21 11:00:21 -0700152static void sysc_write(struct sysc *ddata, int offset, u32 value)
Faiz Abbas596e7952018-07-09 22:18:39 +0530153{
Tony Lindgren5aa91292019-05-27 04:51:53 -0700154 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
155 writew_relaxed(value & 0xffff, ddata->module_va + offset);
156
157 /* Only i2c revision has LO and HI register with stride of 4 */
158 if (ddata->offsets[SYSC_REVISION] >= 0 &&
159 offset == ddata->offsets[SYSC_REVISION]) {
160 u16 hi = value >> 16;
161
162 writew_relaxed(hi, ddata->module_va + offset + 4);
163 }
164
165 return;
166 }
167
Faiz Abbas596e7952018-07-09 22:18:39 +0530168 writel_relaxed(value, ddata->module_va + offset);
169}
170
Tony Lindgren566a9b052017-12-15 09:41:19 -0800171static u32 sysc_read(struct sysc *ddata, int offset)
172{
173 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
174 u32 val;
175
176 val = readw_relaxed(ddata->module_va + offset);
Tony Lindgren5aa91292019-05-27 04:51:53 -0700177
178 /* Only i2c revision has LO and HI register with stride of 4 */
179 if (ddata->offsets[SYSC_REVISION] >= 0 &&
180 offset == ddata->offsets[SYSC_REVISION]) {
181 u16 tmp = readw_relaxed(ddata->module_va + offset + 4);
182
183 val |= tmp << 16;
184 }
Tony Lindgren566a9b052017-12-15 09:41:19 -0800185
186 return val;
187 }
188
189 return readl_relaxed(ddata->module_va + offset);
190}
191
Tony Lindgren09dfe582018-04-16 10:25:52 -0700192static bool sysc_opt_clks_needed(struct sysc *ddata)
193{
194 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
195}
196
Tony Lindgren0eecc632017-10-10 14:23:43 -0700197static u32 sysc_read_revision(struct sysc *ddata)
198{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800199 int offset = ddata->offsets[SYSC_REVISION];
200
201 if (offset < 0)
202 return 0;
203
204 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700205}
206
Tony Lindgrene0db94f2019-05-27 04:51:53 -0700207static u32 sysc_read_sysconfig(struct sysc *ddata)
208{
209 int offset = ddata->offsets[SYSC_SYSCONFIG];
210
211 if (offset < 0)
212 return 0;
213
214 return sysc_read(ddata, offset);
215}
216
217static u32 sysc_read_sysstatus(struct sysc *ddata)
218{
219 int offset = ddata->offsets[SYSC_SYSSTATUS];
220
221 if (offset < 0)
222 return 0;
223
224 return sysc_read(ddata, offset);
225}
226
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300227static int sysc_poll_reset_sysstatus(struct sysc *ddata)
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700228{
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300229 int error, retries;
230 u32 syss_done, rstval;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700231
232 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
233 syss_done = 0;
234 else
235 syss_done = ddata->cfg.syss_mask;
236
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300237 if (likely(!timekeeping_suspended)) {
Tony Lindgren9f911392020-07-02 10:44:20 -0700238 error = readx_poll_timeout_atomic(sysc_read_sysstatus, ddata,
239 rstval, (rstval & ddata->cfg.syss_mask) ==
240 syss_done, 100, MAX_MODULE_SOFTRESET_WAIT);
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300241 } else {
242 retries = MAX_MODULE_SOFTRESET_WAIT;
243 while (retries--) {
244 rstval = sysc_read_sysstatus(ddata);
245 if ((rstval & ddata->cfg.syss_mask) == syss_done)
246 return 0;
247 udelay(2); /* Account for udelay flakeyness */
248 }
249 error = -ETIMEDOUT;
250 }
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700251
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300252 return error;
253}
254
255static int sysc_poll_reset_sysconfig(struct sysc *ddata)
256{
257 int error, retries;
258 u32 sysc_mask, rstval;
259
260 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
261
262 if (likely(!timekeeping_suspended)) {
Tony Lindgren9f911392020-07-02 10:44:20 -0700263 error = readx_poll_timeout_atomic(sysc_read_sysconfig, ddata,
264 rstval, !(rstval & sysc_mask),
265 100, MAX_MODULE_SOFTRESET_WAIT);
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300266 } else {
267 retries = MAX_MODULE_SOFTRESET_WAIT;
268 while (retries--) {
269 rstval = sysc_read_sysconfig(ddata);
270 if (!(rstval & sysc_mask))
271 return 0;
272 udelay(2); /* Account for udelay flakeyness */
273 }
274 error = -ETIMEDOUT;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700275 }
276
277 return error;
278}
279
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300280/* Poll on reset status */
281static int sysc_wait_softreset(struct sysc *ddata)
282{
283 int syss_offset, error = 0;
284
285 if (ddata->cap->regbits->srst_shift < 0)
286 return 0;
287
288 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
289
290 if (syss_offset >= 0)
291 error = sysc_poll_reset_sysstatus(ddata);
292 else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS)
293 error = sysc_poll_reset_sysconfig(ddata);
294
295 return error;
296}
297
Tony Lindgrena54275f2019-03-21 11:00:21 -0700298static int sysc_add_named_clock_from_child(struct sysc *ddata,
299 const char *name,
300 const char *optfck_name)
301{
302 struct device_node *np = ddata->dev->of_node;
303 struct device_node *child;
304 struct clk_lookup *cl;
305 struct clk *clock;
306 const char *n;
307
308 if (name)
309 n = name;
310 else
311 n = optfck_name;
312
313 /* Does the clock alias already exist? */
314 clock = of_clk_get_by_name(np, n);
315 if (!IS_ERR(clock)) {
316 clk_put(clock);
317
318 return 0;
319 }
320
321 child = of_get_next_available_child(np, NULL);
322 if (!child)
323 return -ENODEV;
324
325 clock = devm_get_clk_from_child(ddata->dev, child, name);
326 if (IS_ERR(clock))
327 return PTR_ERR(clock);
328
329 /*
330 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
331 * limit for clk_get(). If cl ever needs to be freed, it should be done
332 * with clkdev_drop().
333 */
Zheng Yongjund995d3d2020-12-29 21:51:47 +0800334 cl = kzalloc(sizeof(*cl), GFP_KERNEL);
Tony Lindgrena54275f2019-03-21 11:00:21 -0700335 if (!cl)
336 return -ENOMEM;
337
338 cl->con_id = n;
339 cl->dev_id = dev_name(ddata->dev);
340 cl->clk = clock;
341 clkdev_add(cl);
342
343 clk_put(clock);
344
345 return 0;
346}
347
348static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
349{
350 const char *optfck_name;
351 int error, index;
352
353 if (ddata->nr_clocks < SYSC_OPTFCK0)
354 index = SYSC_OPTFCK0;
355 else
356 index = ddata->nr_clocks;
357
358 if (name)
359 optfck_name = name;
360 else
361 optfck_name = clock_names[index];
362
363 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
364 if (error)
365 return error;
366
367 ddata->clock_roles[index] = optfck_name;
368 ddata->nr_clocks++;
369
370 return 0;
371}
372
Tony Lindgren09dfe582018-04-16 10:25:52 -0700373static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700374{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700375 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700376
Tony Lindgren09dfe582018-04-16 10:25:52 -0700377 if (!strncmp(clock_names[SYSC_FCK], name, 3))
378 index = SYSC_FCK;
379 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
380 index = SYSC_ICK;
381
382 if (index < 0) {
383 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700384 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700385 index = i;
386 break;
387 }
388 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700389 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700390
391 if (index < 0) {
392 dev_err(ddata->dev, "clock %s not added\n", name);
393 return index;
394 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700395
396 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
397 if (IS_ERR(ddata->clocks[index])) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700398 dev_err(ddata->dev, "clock get error for %s: %li\n",
399 name, PTR_ERR(ddata->clocks[index]));
400
401 return PTR_ERR(ddata->clocks[index]);
402 }
403
404 error = clk_prepare(ddata->clocks[index]);
405 if (error) {
406 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
407 name, error);
408
409 return error;
410 }
411
412 return 0;
413}
414
415static int sysc_get_clocks(struct sysc *ddata)
416{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700417 struct device_node *np = ddata->dev->of_node;
418 struct property *prop;
419 const char *name;
420 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700421
Kees Cook20749052018-06-18 10:45:49 -0700422 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700423 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700424 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700425 GFP_KERNEL);
426 if (!ddata->clock_roles)
427 return -ENOMEM;
428
429 of_property_for_each_string(np, "clock-names", prop, name) {
430 if (!strncmp(clock_names[SYSC_FCK], name, 3))
431 nr_fck++;
432 if (!strncmp(clock_names[SYSC_ICK], name, 3))
433 nr_ick++;
434 ddata->clock_roles[ddata->nr_clocks] = name;
435 ddata->nr_clocks++;
436 }
437
438 if (ddata->nr_clocks < 1)
439 return 0;
440
Tony Lindgrena54275f2019-03-21 11:00:21 -0700441 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
442 error = sysc_init_ext_opt_clock(ddata, NULL);
443 if (error)
444 return error;
445 }
446
Tony Lindgren09dfe582018-04-16 10:25:52 -0700447 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
448 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
449
450 return -EINVAL;
451 }
452
453 if (nr_fck > 1 || nr_ick > 1) {
454 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
455
456 return -EINVAL;
457 }
458
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800459 /* Always add a slot for main clocks fck and ick even if unused */
460 if (!nr_fck)
461 ddata->nr_clocks++;
462 if (!nr_ick)
463 ddata->nr_clocks++;
464
Kees Cook20749052018-06-18 10:45:49 -0700465 ddata->clocks = devm_kcalloc(ddata->dev,
466 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700467 GFP_KERNEL);
468 if (!ddata->clocks)
469 return -ENOMEM;
470
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800471 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
472 const char *name = ddata->clock_roles[i];
473
474 if (!name)
475 continue;
476
477 error = sysc_get_one_clock(ddata, name);
Tony Lindgren2783d062019-09-05 13:01:29 -0700478 if (error)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700479 return error;
480 }
481
482 return 0;
483}
484
Tony Lindgrend8789702019-03-21 11:00:21 -0700485static int sysc_enable_main_clocks(struct sysc *ddata)
486{
487 struct clk *clock;
488 int i, error;
489
490 if (!ddata->clocks)
491 return 0;
492
493 for (i = 0; i < SYSC_OPTFCK0; i++) {
494 clock = ddata->clocks[i];
495
496 /* Main clocks may not have ick */
497 if (IS_ERR_OR_NULL(clock))
498 continue;
499
500 error = clk_enable(clock);
501 if (error)
502 goto err_disable;
503 }
504
505 return 0;
506
507err_disable:
508 for (i--; i >= 0; i--) {
509 clock = ddata->clocks[i];
510
511 /* Main clocks may not have ick */
512 if (IS_ERR_OR_NULL(clock))
513 continue;
514
515 clk_disable(clock);
516 }
517
518 return error;
519}
520
521static void sysc_disable_main_clocks(struct sysc *ddata)
522{
523 struct clk *clock;
524 int i;
525
526 if (!ddata->clocks)
527 return;
528
529 for (i = 0; i < SYSC_OPTFCK0; i++) {
530 clock = ddata->clocks[i];
531 if (IS_ERR_OR_NULL(clock))
532 continue;
533
534 clk_disable(clock);
535 }
536}
537
538static int sysc_enable_opt_clocks(struct sysc *ddata)
539{
540 struct clk *clock;
541 int i, error;
542
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800543 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700544 return 0;
545
546 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
547 clock = ddata->clocks[i];
548
549 /* Assume no holes for opt clocks */
550 if (IS_ERR_OR_NULL(clock))
551 return 0;
552
553 error = clk_enable(clock);
554 if (error)
555 goto err_disable;
556 }
557
558 return 0;
559
560err_disable:
561 for (i--; i >= 0; i--) {
562 clock = ddata->clocks[i];
563 if (IS_ERR_OR_NULL(clock))
564 continue;
565
566 clk_disable(clock);
567 }
568
569 return error;
570}
571
572static void sysc_disable_opt_clocks(struct sysc *ddata)
573{
574 struct clk *clock;
575 int i;
576
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800577 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700578 return;
579
580 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
581 clock = ddata->clocks[i];
582
583 /* Assume no holes for opt clocks */
584 if (IS_ERR_OR_NULL(clock))
585 return;
586
587 clk_disable(clock);
588 }
589}
590
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700591static void sysc_clkdm_deny_idle(struct sysc *ddata)
592{
593 struct ti_sysc_platform_data *pdata;
594
Tony Lindgren94f63452019-12-12 08:57:58 -0800595 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700596 return;
597
598 pdata = dev_get_platdata(ddata->dev);
599 if (pdata && pdata->clkdm_deny_idle)
600 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
601}
602
603static void sysc_clkdm_allow_idle(struct sysc *ddata)
604{
605 struct ti_sysc_platform_data *pdata;
606
Tony Lindgren94f63452019-12-12 08:57:58 -0800607 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700608 return;
609
610 pdata = dev_get_platdata(ddata->dev);
611 if (pdata && pdata->clkdm_allow_idle)
612 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
613}
614
Tony Lindgren0eecc632017-10-10 14:23:43 -0700615/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700616 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700617 * @ddata: device driver data
618 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700619 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700620 */
621static int sysc_init_resets(struct sysc *ddata)
622{
Tony Lindgren50622362018-04-16 10:20:27 -0700623 ddata->rsts =
Tero Kristobb88b862019-08-07 15:46:05 +0300624 devm_reset_control_get_optional_shared(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700625
zhengbin3f2c4202019-11-18 18:37:32 +0800626 return PTR_ERR_OR_ZERO(ddata->rsts);
Tony Lindgren50622362018-04-16 10:20:27 -0700627}
628
629/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700630 * sysc_parse_and_check_child_range - parses module IO region from ranges
631 * @ddata: device driver data
632 *
633 * In general we only need rev, syss, and sysc registers and not the whole
634 * module range. But we do want the offsets for these registers from the
635 * module base. This allows us to check them against the legacy hwmod
636 * platform data. Let's also check the ranges are configured properly.
637 */
638static int sysc_parse_and_check_child_range(struct sysc *ddata)
639{
640 struct device_node *np = ddata->dev->of_node;
641 const __be32 *ranges;
642 u32 nr_addr, nr_size;
643 int len, error;
644
645 ranges = of_get_property(np, "ranges", &len);
646 if (!ranges) {
647 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
648
649 return -ENOENT;
650 }
651
652 len /= sizeof(*ranges);
653
654 if (len < 3) {
655 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
656
657 return -EINVAL;
658 }
659
660 error = of_property_read_u32(np, "#address-cells", &nr_addr);
661 if (error)
662 return -ENOENT;
663
664 error = of_property_read_u32(np, "#size-cells", &nr_size);
665 if (error)
666 return -ENOENT;
667
668 if (nr_addr != 1 || nr_size != 1) {
669 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
670
671 return -EINVAL;
672 }
673
674 ranges++;
675 ddata->module_pa = of_translate_address(np, ranges++);
676 ddata->module_size = be32_to_cpup(ranges);
677
Tony Lindgren0eecc632017-10-10 14:23:43 -0700678 return 0;
679}
680
Tony Lindgren4700a002021-03-08 11:35:07 +0200681/* Interconnect instances to probe before l4_per instances */
682static struct resource early_bus_ranges[] = {
683 /* am3/4 l4_wkup */
684 { .start = 0x44c00000, .end = 0x44c00000 + 0x300000, },
685 /* omap4/5 and dra7 l4_cfg */
686 { .start = 0x4a000000, .end = 0x4a000000 + 0x300000, },
687 /* omap4 l4_wkup */
688 { .start = 0x4a300000, .end = 0x4a300000 + 0x30000, },
689 /* omap5 and dra7 l4_wkup without dra7 dcan segment */
690 { .start = 0x4ae00000, .end = 0x4ae00000 + 0x30000, },
691};
692
693static atomic_t sysc_defer = ATOMIC_INIT(10);
694
695/**
696 * sysc_defer_non_critical - defer non_critical interconnect probing
697 * @ddata: device driver data
698 *
699 * We want to probe l4_cfg and l4_wkup interconnect instances before any
700 * l4_per instances as l4_per instances depend on resources on l4_cfg and
701 * l4_wkup interconnects.
702 */
703static int sysc_defer_non_critical(struct sysc *ddata)
704{
705 struct resource *res;
706 int i;
707
708 if (!atomic_read(&sysc_defer))
709 return 0;
710
711 for (i = 0; i < ARRAY_SIZE(early_bus_ranges); i++) {
712 res = &early_bus_ranges[i];
713 if (ddata->module_pa >= res->start &&
714 ddata->module_pa <= res->end) {
715 atomic_set(&sysc_defer, 0);
716
717 return 0;
718 }
719 }
720
721 atomic_dec_if_positive(&sysc_defer);
722
723 return -EPROBE_DEFER;
724}
725
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800726static struct device_node *stdout_path;
727
728static void sysc_init_stdout_path(struct sysc *ddata)
729{
730 struct device_node *np = NULL;
731 const char *uart;
732
733 if (IS_ERR(stdout_path))
734 return;
735
736 if (stdout_path)
737 return;
738
739 np = of_find_node_by_path("/chosen");
740 if (!np)
741 goto err;
742
743 uart = of_get_property(np, "stdout-path", NULL);
744 if (!uart)
745 goto err;
746
747 np = of_find_node_by_path(uart);
748 if (!np)
749 goto err;
750
751 stdout_path = np;
752
753 return;
754
755err:
756 stdout_path = ERR_PTR(-ENODEV);
757}
758
759static void sysc_check_quirk_stdout(struct sysc *ddata,
760 struct device_node *np)
761{
762 sysc_init_stdout_path(ddata);
763 if (np != stdout_path)
764 return;
765
766 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
767 SYSC_QUIRK_NO_RESET_ON_INIT;
768}
769
Tony Lindgren0eecc632017-10-10 14:23:43 -0700770/**
771 * sysc_check_one_child - check child configuration
772 * @ddata: device driver data
773 * @np: child device node
774 *
775 * Let's avoid messy situations where we have new interconnect target
776 * node but children have "ti,hwmods". These belong to the interconnect
777 * target node and are managed by this driver.
778 */
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530779static void sysc_check_one_child(struct sysc *ddata,
780 struct device_node *np)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700781{
782 const char *name;
783
784 name = of_get_property(np, "ti,hwmods", NULL);
Tony Lindgren7320fd32020-02-24 12:58:03 -0800785 if (name && !of_device_is_compatible(np, "ti,sysc"))
Tony Lindgren0eecc632017-10-10 14:23:43 -0700786 dev_warn(ddata->dev, "really a child ti,hwmods property?");
787
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800788 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800789 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700790}
791
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530792static void sysc_check_children(struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700793{
794 struct device_node *child;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700795
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530796 for_each_child_of_node(ddata->dev->of_node, child)
797 sysc_check_one_child(ddata, child);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700798}
799
Tony Lindgrena7199e22017-12-15 09:41:14 -0800800/*
801 * So far only I2C uses 16-bit read access with clockactivity with revision
802 * in two registers with stride of 4. We can detect this based on the rev
803 * register size to configure things far enough to be able to properly read
804 * the revision register.
805 */
806static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
807{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800808 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800809 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800810}
811
Tony Lindgren0eecc632017-10-10 14:23:43 -0700812/**
813 * sysc_parse_one - parses the interconnect target module registers
814 * @ddata: device driver data
815 * @reg: register to parse
816 */
817static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
818{
819 struct resource *res;
820 const char *name;
821
822 switch (reg) {
823 case SYSC_REVISION:
824 case SYSC_SYSCONFIG:
825 case SYSC_SYSSTATUS:
826 name = reg_names[reg];
827 break;
828 default:
829 return -EINVAL;
830 }
831
832 res = platform_get_resource_byname(to_platform_device(ddata->dev),
833 IORESOURCE_MEM, name);
834 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700835 ddata->offsets[reg] = -ENODEV;
836
837 return 0;
838 }
839
840 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800841 if (reg == SYSC_REVISION)
842 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700843
844 return 0;
845}
846
847static int sysc_parse_registers(struct sysc *ddata)
848{
849 int i, error;
850
851 for (i = 0; i < SYSC_MAX_REGS; i++) {
852 error = sysc_parse_one(ddata, i);
853 if (error)
854 return error;
855 }
856
857 return 0;
858}
859
860/**
861 * sysc_check_registers - check for misconfigured register overlaps
862 * @ddata: device driver data
863 */
864static int sysc_check_registers(struct sysc *ddata)
865{
866 int i, j, nr_regs = 0, nr_matches = 0;
867
868 for (i = 0; i < SYSC_MAX_REGS; i++) {
869 if (ddata->offsets[i] < 0)
870 continue;
871
872 if (ddata->offsets[i] > (ddata->module_size - 4)) {
873 dev_err(ddata->dev, "register outside module range");
874
875 return -EINVAL;
876 }
877
878 for (j = 0; j < SYSC_MAX_REGS; j++) {
879 if (ddata->offsets[j] < 0)
880 continue;
881
882 if (ddata->offsets[i] == ddata->offsets[j])
883 nr_matches++;
884 }
885 nr_regs++;
886 }
887
Tony Lindgren0eecc632017-10-10 14:23:43 -0700888 if (nr_matches > nr_regs) {
889 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
890 nr_regs, nr_matches);
891
892 return -EINVAL;
893 }
894
895 return 0;
896}
897
898/**
Lee Jones4e001852021-05-26 09:10:37 +0100899 * sysc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700900 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700901 *
902 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700903 * within the interconnect target module range. For example, SGX has
904 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
905 * has them at offset 0x1200 in the CPSW_WR child. Usually the
906 * the interconnect target module registers are at the beginning of
907 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700908 */
909static int sysc_ioremap(struct sysc *ddata)
910{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700911 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700912
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700913 if (ddata->offsets[SYSC_REVISION] < 0 &&
914 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
915 ddata->offsets[SYSC_SYSSTATUS] < 0) {
916 size = ddata->module_size;
917 } else {
918 size = max3(ddata->offsets[SYSC_REVISION],
919 ddata->offsets[SYSC_SYSCONFIG],
920 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700921
Tony Lindgren4e23be42019-06-10 04:48:05 -0700922 if (size < SZ_1K)
923 size = SZ_1K;
924
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700925 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700926 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700927 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700928
Tony Lindgren0eecc632017-10-10 14:23:43 -0700929 ddata->module_va = devm_ioremap(ddata->dev,
930 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700931 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700932 if (!ddata->module_va)
933 return -EIO;
934
935 return 0;
936}
937
938/**
939 * sysc_map_and_check_registers - ioremap and check device registers
940 * @ddata: device driver data
941 */
942static int sysc_map_and_check_registers(struct sysc *ddata)
943{
Tony Lindgren29281352020-11-16 12:57:13 +0200944 struct device_node *np = ddata->dev->of_node;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700945 int error;
946
947 error = sysc_parse_and_check_child_range(ddata);
948 if (error)
949 return error;
950
Tony Lindgren4700a002021-03-08 11:35:07 +0200951 error = sysc_defer_non_critical(ddata);
952 if (error)
953 return error;
954
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530955 sysc_check_children(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700956
Tony Lindgren7bad5af2021-03-08 11:35:06 +0200957 if (!of_get_property(np, "reg", NULL))
958 return 0;
959
Tony Lindgren0eecc632017-10-10 14:23:43 -0700960 error = sysc_parse_registers(ddata);
961 if (error)
962 return error;
963
964 error = sysc_ioremap(ddata);
965 if (error)
966 return error;
967
968 error = sysc_check_registers(ddata);
969 if (error)
970 return error;
971
972 return 0;
973}
974
975/**
976 * sysc_show_rev - read and show interconnect target module revision
977 * @bufp: buffer to print the information to
978 * @ddata: device driver data
979 */
980static int sysc_show_rev(char *bufp, struct sysc *ddata)
981{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800982 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700983
984 if (ddata->offsets[SYSC_REVISION] < 0)
985 return sprintf(bufp, ":NA");
986
Tony Lindgren566a9b052017-12-15 09:41:19 -0800987 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700988
989 return len;
990}
991
992static int sysc_show_reg(struct sysc *ddata,
993 char *bufp, enum sysc_registers reg)
994{
995 if (ddata->offsets[reg] < 0)
996 return sprintf(bufp, ":NA");
997
998 return sprintf(bufp, ":%x", ddata->offsets[reg]);
999}
1000
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001001static int sysc_show_name(char *bufp, struct sysc *ddata)
1002{
1003 if (!ddata->name)
1004 return 0;
1005
1006 return sprintf(bufp, ":%s", ddata->name);
1007}
1008
Tony Lindgren0eecc632017-10-10 14:23:43 -07001009/**
1010 * sysc_show_registers - show information about interconnect target module
1011 * @ddata: device driver data
1012 */
1013static void sysc_show_registers(struct sysc *ddata)
1014{
1015 char buf[128];
1016 char *bufp = buf;
1017 int i;
1018
1019 for (i = 0; i < SYSC_MAX_REGS; i++)
1020 bufp += sysc_show_reg(ddata, bufp, i);
1021
1022 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001023 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001024
1025 dev_dbg(ddata->dev, "%llx:%x%s\n",
1026 ddata->module_pa, ddata->module_size,
1027 buf);
1028}
1029
Tony Lindgrene8639e12020-02-24 12:58:03 -08001030/**
1031 * sysc_write_sysconfig - handle sysconfig quirks for register write
1032 * @ddata: device driver data
1033 * @value: register value
1034 */
1035static void sysc_write_sysconfig(struct sysc *ddata, u32 value)
1036{
1037 if (ddata->module_unlock_quirk)
1038 ddata->module_unlock_quirk(ddata);
1039
1040 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], value);
1041
1042 if (ddata->module_lock_quirk)
1043 ddata->module_lock_quirk(ddata);
1044}
1045
Roger Quadrosd59b6052019-04-08 12:52:39 +03001046#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001047#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +03001048
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001049/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001050static int sysc_enable_module(struct device *dev)
1051{
1052 struct sysc *ddata;
1053 const struct sysc_regbits *regbits;
1054 u32 reg, idlemodes, best_mode;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001055 int error;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001056
1057 ddata = dev_get_drvdata(dev);
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001058
1059 /*
1060 * Some modules like DSS reset automatically on idle. Enable optional
1061 * reset clocks and wait for OCP softreset to complete.
1062 */
1063 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET) {
1064 error = sysc_enable_opt_clocks(ddata);
1065 if (error) {
1066 dev_err(ddata->dev,
1067 "Optional clocks failed for enable: %i\n",
1068 error);
1069 return error;
1070 }
1071 }
Tony Lindgrene275d212020-10-26 10:08:47 +02001072 /*
1073 * Some modules like i2c and hdq1w have unusable reset status unless
1074 * the module reset quirk is enabled. Skip status check on enable.
1075 */
1076 if (!(ddata->cfg.quirks & SYSC_MODULE_QUIRK_ENA_RESETDONE)) {
1077 error = sysc_wait_softreset(ddata);
1078 if (error)
1079 dev_warn(ddata->dev, "OCP softreset timed out\n");
1080 }
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001081 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET)
1082 sysc_disable_opt_clocks(ddata);
1083
1084 /*
1085 * Some subsystem private interconnects, like DSS top level module,
1086 * need only the automatic OCP softreset handling with no sysconfig
1087 * register bits to configure.
1088 */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001089 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1090 return 0;
1091
Roger Quadrosd59b6052019-04-08 12:52:39 +03001092 regbits = ddata->cap->regbits;
1093 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1094
Tony Lindgren08b91dd2020-05-31 12:37:54 -07001095 /*
1096 * Set CLOCKACTIVITY, we only use it for ick. And we only configure it
1097 * based on the SYSC_QUIRK_USE_CLOCKACT flag, not based on the hardware
1098 * capabilities. See the old HWMOD_SET_DEFAULT_CLOCKACT flag.
1099 */
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001100 if (regbits->clkact_shift >= 0 &&
Tony Lindgren08b91dd2020-05-31 12:37:54 -07001101 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT))
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001102 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
1103
Roger Quadrosd59b6052019-04-08 12:52:39 +03001104 /* Set SIDLE mode */
1105 idlemodes = ddata->cfg.sidlemodes;
1106 if (!idlemodes || regbits->sidle_shift < 0)
1107 goto set_midle;
1108
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001109 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
1110 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
1111 best_mode = SYSC_IDLE_NO;
1112 } else {
1113 best_mode = fls(ddata->cfg.sidlemodes) - 1;
1114 if (best_mode > SYSC_IDLE_MASK) {
1115 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1116 return -EINVAL;
1117 }
Tony Lindgren6e09f492019-05-27 04:51:55 -07001118
1119 /* Set WAKEUP */
1120 if (regbits->enwkup_shift >= 0 &&
1121 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
1122 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001123 }
1124
1125 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1126 reg |= best_mode << regbits->sidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001127 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001128
1129set_midle:
1130 /* Set MIDLE mode */
1131 idlemodes = ddata->cfg.midlemodes;
1132 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -07001133 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001134
1135 best_mode = fls(ddata->cfg.midlemodes) - 1;
1136 if (best_mode > SYSC_IDLE_MASK) {
1137 dev_err(dev, "%s: invalid midlemode\n", __func__);
1138 return -EINVAL;
1139 }
1140
Tony Lindgren03856e92019-10-21 13:36:09 -07001141 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_MSTANDBY)
1142 best_mode = SYSC_IDLE_NO;
1143
Roger Quadrosd59b6052019-04-08 12:52:39 +03001144 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1145 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001146 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001147
Tony Lindgreneec26552019-05-27 04:51:54 -07001148set_autoidle:
1149 /* Autoidle bit must enabled separately if available */
1150 if (regbits->autoidle_shift >= 0 &&
1151 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
1152 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001153 sysc_write_sysconfig(ddata, reg);
Tony Lindgreneec26552019-05-27 04:51:54 -07001154 }
1155
Tony Lindgren5ce8aee2020-05-27 06:49:29 -07001156 /* Flush posted write */
1157 sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1158
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001159 if (ddata->module_enable_quirk)
1160 ddata->module_enable_quirk(ddata);
1161
Roger Quadrosd59b6052019-04-08 12:52:39 +03001162 return 0;
1163}
1164
1165static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
1166{
1167 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
1168 *best_mode = SYSC_IDLE_SMART_WKUP;
1169 else if (idlemodes & BIT(SYSC_IDLE_SMART))
1170 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -07001171 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +03001172 *best_mode = SYSC_IDLE_FORCE;
1173 else
1174 return -EINVAL;
1175
1176 return 0;
1177}
1178
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001179/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001180static int sysc_disable_module(struct device *dev)
1181{
1182 struct sysc *ddata;
1183 const struct sysc_regbits *regbits;
1184 u32 reg, idlemodes, best_mode;
1185 int ret;
1186
1187 ddata = dev_get_drvdata(dev);
1188 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1189 return 0;
1190
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001191 if (ddata->module_disable_quirk)
1192 ddata->module_disable_quirk(ddata);
1193
Roger Quadrosd59b6052019-04-08 12:52:39 +03001194 regbits = ddata->cap->regbits;
1195 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1196
1197 /* Set MIDLE mode */
1198 idlemodes = ddata->cfg.midlemodes;
1199 if (!idlemodes || regbits->midle_shift < 0)
1200 goto set_sidle;
1201
1202 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1203 if (ret) {
1204 dev_err(dev, "%s: invalid midlemode\n", __func__);
1205 return ret;
1206 }
1207
Tony Lindgren93c60482019-12-09 13:55:15 -08001208 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_MSTANDBY) ||
1209 ddata->cfg.quirks & (SYSC_QUIRK_FORCE_MSTANDBY))
Tony Lindgren03856e92019-10-21 13:36:09 -07001210 best_mode = SYSC_IDLE_FORCE;
1211
Roger Quadrosd59b6052019-04-08 12:52:39 +03001212 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1213 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001214 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001215
1216set_sidle:
1217 /* Set SIDLE mode */
1218 idlemodes = ddata->cfg.sidlemodes;
1219 if (!idlemodes || regbits->sidle_shift < 0)
1220 return 0;
1221
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001222 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
1223 best_mode = SYSC_IDLE_FORCE;
1224 } else {
1225 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1226 if (ret) {
1227 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1228 return ret;
1229 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001230 }
1231
1232 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1233 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -07001234 if (regbits->autoidle_shift >= 0 &&
1235 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1236 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001237 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001238
Tony Lindgren5ce8aee2020-05-27 06:49:29 -07001239 /* Flush posted write */
1240 sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1241
Roger Quadrosd59b6052019-04-08 12:52:39 +03001242 return 0;
1243}
1244
Tony Lindgrenff437282019-03-21 11:00:21 -07001245static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1246 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001247{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001248 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001249 int error;
1250
1251 pdata = dev_get_platdata(ddata->dev);
1252 if (!pdata)
1253 return 0;
1254
1255 if (!pdata->idle_module)
1256 return -ENODEV;
1257
1258 error = pdata->idle_module(dev, &ddata->cookie);
1259 if (error)
1260 dev_err(dev, "%s: could not idle: %i\n",
1261 __func__, error);
1262
Tero Kristo4345f0d2019-08-07 15:46:04 +03001263 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001264
Tony Lindgrenff437282019-03-21 11:00:21 -07001265 return 0;
1266}
1267
1268static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1269 struct sysc *ddata)
1270{
1271 struct ti_sysc_platform_data *pdata;
1272 int error;
1273
1274 pdata = dev_get_platdata(ddata->dev);
1275 if (!pdata)
1276 return 0;
1277
1278 if (!pdata->enable_module)
1279 return -ENODEV;
1280
1281 error = pdata->enable_module(dev, &ddata->cookie);
1282 if (error)
1283 dev_err(dev, "%s: could not enable: %i\n",
1284 __func__, error);
1285
Tero Kristobf59ebb2019-10-07 15:29:29 +03001286 reset_control_deassert(ddata->rsts);
1287
Tony Lindgrenff437282019-03-21 11:00:21 -07001288 return 0;
1289}
1290
1291static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1292{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001293 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001294 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001295
1296 ddata = dev_get_drvdata(dev);
1297
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001298 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001299 return 0;
1300
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001301 sysc_clkdm_deny_idle(ddata);
1302
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001303 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001304 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001305 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001306 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001307 } else {
1308 error = sysc_disable_module(dev);
1309 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001310 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001311 }
1312
Tony Lindgrend8789702019-03-21 11:00:21 -07001313 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001314
Tony Lindgrend8789702019-03-21 11:00:21 -07001315 if (sysc_opt_clks_needed(ddata))
1316 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001317
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001318 ddata->enabled = false;
1319
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001320err_allow_idle:
Tero Kristob6036312019-08-07 15:46:03 +03001321 sysc_clkdm_allow_idle(ddata);
1322
Tony Lindgren4097c9a2020-11-16 12:57:13 +02001323 reset_control_assert(ddata->rsts);
1324
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001325 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001326}
1327
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001328static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001329{
1330 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001331 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001332
1333 ddata = dev_get_drvdata(dev);
1334
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001335 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001336 return 0;
1337
Tony Lindgren8383e252019-05-27 04:51:56 -07001338
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001339 sysc_clkdm_deny_idle(ddata);
1340
Tony Lindgrend8789702019-03-21 11:00:21 -07001341 if (sysc_opt_clks_needed(ddata)) {
1342 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001343 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001344 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001345 }
1346
Tony Lindgrend8789702019-03-21 11:00:21 -07001347 error = sysc_enable_main_clocks(ddata);
1348 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001349 goto err_opt_clocks;
1350
Tero Kristobf59ebb2019-10-07 15:29:29 +03001351 reset_control_deassert(ddata->rsts);
1352
Tony Lindgren93de83a2019-03-21 11:00:21 -07001353 if (ddata->legacy_mode) {
1354 error = sysc_runtime_resume_legacy(dev, ddata);
1355 if (error)
1356 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001357 } else {
1358 error = sysc_enable_module(dev);
1359 if (error)
1360 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001361 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001362
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001363 ddata->enabled = true;
1364
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001365 sysc_clkdm_allow_idle(ddata);
1366
Tony Lindgrend8789702019-03-21 11:00:21 -07001367 return 0;
1368
1369err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001370 sysc_disable_main_clocks(ddata);
1371err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001372 if (sysc_opt_clks_needed(ddata))
1373 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001374err_allow_idle:
1375 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001376
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001377 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001378}
1379
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001380static int sysc_reinit_module(struct sysc *ddata, bool leave_enabled)
1381{
1382 struct device *dev = ddata->dev;
1383 int error;
1384
1385 /* Disable target module if it is enabled */
1386 if (ddata->enabled) {
1387 error = sysc_runtime_suspend(dev);
1388 if (error)
1389 dev_warn(dev, "reinit suspend failed: %i\n", error);
1390 }
1391
1392 /* Enable target module */
1393 error = sysc_runtime_resume(dev);
1394 if (error)
1395 dev_warn(dev, "reinit resume failed: %i\n", error);
1396
1397 if (leave_enabled)
1398 return error;
1399
1400 /* Disable target module if no leave_enabled was set */
1401 error = sysc_runtime_suspend(dev);
1402 if (error)
1403 dev_warn(dev, "reinit suspend failed: %i\n", error);
1404
1405 return error;
1406}
1407
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001408static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001409{
1410 struct sysc *ddata;
1411
1412 ddata = dev_get_drvdata(dev);
1413
Tony Lindgrena55de412020-07-02 13:57:14 -07001414 if (ddata->cfg.quirks &
1415 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
Tony Lindgrene7420c22018-04-16 10:26:46 -07001416 return 0;
1417
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001418 if (!ddata->enabled)
1419 return 0;
1420
1421 ddata->needs_resume = 1;
1422
1423 return sysc_runtime_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001424}
1425
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001426static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001427{
1428 struct sysc *ddata;
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001429 int error = 0;
Tony Lindgren62020f22018-02-22 13:59:44 -08001430
1431 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001432
Tony Lindgrena55de412020-07-02 13:57:14 -07001433 if (ddata->cfg.quirks &
1434 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
Tony Lindgrene7420c22018-04-16 10:26:46 -07001435 return 0;
1436
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001437 if (ddata->cfg.quirks & SYSC_QUIRK_REINIT_ON_RESUME) {
1438 error = sysc_reinit_module(ddata, ddata->needs_resume);
1439 if (error)
1440 dev_warn(dev, "noirq_resume failed: %i\n", error);
1441 } else if (ddata->needs_resume) {
1442 error = sysc_runtime_resume(dev);
1443 if (error)
1444 dev_warn(dev, "noirq_resume failed: %i\n", error);
1445 }
1446
1447 ddata->needs_resume = 0;
1448
1449 return error;
Tony Lindgrene7420c22018-04-16 10:26:46 -07001450}
1451
Tony Lindgren0eecc632017-10-10 14:23:43 -07001452static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001453 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001454 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1455 sysc_runtime_resume,
1456 NULL)
1457};
1458
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001459/* Module revision register based quirks */
1460struct sysc_revision_quirk {
1461 const char *name;
1462 u32 base;
1463 int rev_offset;
1464 int sysc_offset;
1465 int syss_offset;
1466 u32 revision;
1467 u32 revision_mask;
1468 u32 quirks;
1469};
1470
1471#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1472 optrev_val, optrevmask, optquirkmask) \
1473 { \
1474 .name = (optname), \
1475 .base = (optbase), \
1476 .rev_offset = (optrev), \
1477 .sysc_offset = (optsysc), \
1478 .syss_offset = (optsyss), \
1479 .revision = (optrev_val), \
1480 .revision_mask = (optrevmask), \
1481 .quirks = (optquirkmask), \
1482 }
1483
1484static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1485 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001486 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -07001487 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001488 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1489 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001490 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1491 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001492 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001493 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001494 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001495 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001496 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001497 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001498 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001499
Tony Lindgrena54275f2019-03-21 11:00:21 -07001500 /* Quirks that need to be set based on the module address */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001501 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -ENODEV, 0x50000800, 0xffffffff,
Tony Lindgrena54275f2019-03-21 11:00:21 -07001502 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1503 SYSC_QUIRK_SWSUP_SIDLE),
1504
Tony Lindgren4e23be42019-06-10 04:48:05 -07001505 /* Quirks that need to be set based on detected module */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001506 SYSC_QUIRK("aess", 0, 0, 0x10, -ENODEV, 0x40000000, 0xffffffff,
Tony Lindgren020003f2019-11-14 08:25:28 -08001507 SYSC_MODULE_QUIRK_AESS),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001508 SYSC_QUIRK("dcan", 0x48480000, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001509 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001510 SYSC_QUIRK("dss", 0x4832a000, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001511 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001512 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000040, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001513 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001514 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000061, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001515 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001516 SYSC_QUIRK("dwc3", 0x48880000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001517 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001518 SYSC_QUIRK("dwc3", 0x488c0000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001519 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgrencfeeea62020-11-16 12:57:13 +02001520 SYSC_QUIRK("gpmc", 0, 0, 0x10, 0x14, 0x00000060, 0xffffffff,
1521 SYSC_QUIRK_GPMC_DEBUG),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001522 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50030200, 0xffffffff,
1523 SYSC_QUIRK_OPT_CLKS_NEEDED),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001524 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001525 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001526 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001527 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001528 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001529 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001530 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001531 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001532 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001533 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001534 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
Tony Lindgrene275d212020-10-26 10:08:47 +02001535 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001536 SYSC_QUIRK("gpu", 0x50000000, 0x14, -ENODEV, -ENODEV, 0x00010201, 0xffffffff, 0),
1537 SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff,
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001538 SYSC_MODULE_QUIRK_SGX),
Tony Lindgrenaef067e2020-03-10 09:06:02 -07001539 SYSC_QUIRK("lcdc", 0, 0, 0x54, -ENODEV, 0x4f201000, 0xffffffff,
1540 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Peter Ujfalusi8122dc52021-07-17 15:09:24 +03001541 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44306302, 0xffffffff,
1542 SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgrene8639e12020-02-24 12:58:03 -08001543 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -ENODEV, 0x4eb01908, 0xffff00f0,
1544 SYSC_MODULE_QUIRK_RTC_UNLOCK),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001545 SYSC_QUIRK("tptc", 0, 0, 0x10, -ENODEV, 0x40006c00, 0xffffefff,
1546 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1547 SYSC_QUIRK("tptc", 0, 0, -ENODEV, -ENODEV, 0x40007c00, 0xffffffff,
1548 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgrendb8e7122021-05-07 12:09:03 +03001549 SYSC_QUIRK("sata", 0, 0xfc, 0x1100, -ENODEV, 0x5e412000, 0xffffffff,
1550 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren42546322020-07-13 09:59:47 -07001551 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff,
1552 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1553 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -ENODEV, 0x50700101, 0xffffffff,
1554 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren03856e92019-10-21 13:36:09 -07001555 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1556 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001557 SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -ENODEV, 0x4ea2080d, 0xffffffff,
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001558 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
1559 SYSC_QUIRK_REINIT_ON_RESUME),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001560 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1561 SYSC_MODULE_QUIRK_WDT),
Suman Annab2745d92020-02-27 16:28:34 -06001562 /* PRUSS on am3, am4 and am5 */
1563 SYSC_QUIRK("pruss", 0, 0x26000, 0x26004, -ENODEV, 0x47000000, 0xff000000,
1564 SYSC_MODULE_QUIRK_PRUSS),
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001565 /* Watchdog on am3 and am4 */
1566 SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1567 SYSC_MODULE_QUIRK_WDT | SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001568
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001569#ifdef DEBUG
Tony Lindgren590e15c2020-02-24 12:58:03 -08001570 SYSC_QUIRK("adc", 0, 0, 0x10, -ENODEV, 0x47300001, 0xffffffff, 0),
1571 SYSC_QUIRK("atl", 0, 0, -ENODEV, -ENODEV, 0x0a070100, 0xffffffff, 0),
1572 SYSC_QUIRK("cm", 0, 0, -ENODEV, -ENODEV, 0x40000301, 0xffffffff, 0),
1573 SYSC_QUIRK("control", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001574 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001575 0xffff00f0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001576 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff, 0),
1577 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001578 SYSC_QUIRK("dispc", 0x4832a400, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1579 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1580 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000051, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001581 SYSC_QUIRK("dmic", 0, 0, 0x10, -ENODEV, 0x50010000, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001582 SYSC_QUIRK("dsi", 0x58004000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1583 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1584 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1585 SYSC_QUIRK("dsi", 0x58009000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001586 SYSC_QUIRK("dwc3", 0, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, 0),
Tony Lindgren7edd00f2019-08-14 05:18:16 -07001587 SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1588 SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001589 SYSC_QUIRK("elm", 0x48080000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
1590 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x40441403, 0xffff0fff, 0),
1591 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x50440500, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001592 SYSC_QUIRK("epwmss", 0, 0, 0x4, -ENODEV, 0x47400001, 0xffffffff, 0),
1593 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -ENODEV, 0, 0, 0),
1594 SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001595 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50031d00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001596 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001597 SYSC_QUIRK("iss", 0, 0, 0x10, -ENODEV, 0x40000101, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001598 SYSC_QUIRK("keypad", 0x4a31c000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001599 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44307b02, 0xffffffff, 0),
1600 SYSC_QUIRK("mcbsp", 0, -ENODEV, 0x8c, -ENODEV, 0, 0, 0),
1601 SYSC_QUIRK("mcspi", 0, 0, 0x10, -ENODEV, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001602 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001603 SYSC_QUIRK("mailbox", 0, 0, 0x10, -ENODEV, 0x00000400, 0xffffffff, 0),
1604 SYSC_QUIRK("m3", 0, 0, -ENODEV, -ENODEV, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001605 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001606 SYSC_QUIRK("ocp2scp", 0, 0, -ENODEV, -ENODEV, 0x50060007, 0xffffffff, 0),
1607 SYSC_QUIRK("padconf", 0, 0, 0x10, -ENODEV, 0x4fff0800, 0xffffffff, 0),
1608 SYSC_QUIRK("padconf", 0, 0, -ENODEV, -ENODEV, 0x40001100, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001609 SYSC_QUIRK("pcie", 0x51000000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
1610 SYSC_QUIRK("pcie", 0x51800000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001611 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000100, 0xffffffff, 0),
1612 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x00004102, 0xffffffff, 0),
1613 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000400, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001614 SYSC_QUIRK("rfbi", 0x4832a800, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1615 SYSC_QUIRK("rfbi", 0x58002000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001616 SYSC_QUIRK("scm", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
1617 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4e8b0100, 0xffffffff, 0),
1618 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4f000100, 0xffffffff, 0),
1619 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x40000900, 0xffffffff, 0),
1620 SYSC_QUIRK("scrm", 0, 0, -ENODEV, -ENODEV, 0x00000010, 0xffffffff, 0),
1621 SYSC_QUIRK("sdio", 0, 0, 0x10, -ENODEV, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001622 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001623 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001624 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40000902, 0xffffffff, 0),
1625 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40002903, 0xffffffff, 0),
Tony Lindgrened4520d2021-08-09 11:27:47 -05001626 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x24, -ENODEV, 0x00000000, 0xffffffff, 0),
1627 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x38, -ENODEV, 0x00000000, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001628 SYSC_QUIRK("spinlock", 0, 0, 0x10, -ENODEV, 0x50020000, 0xffffffff, 0),
1629 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -ENODEV, 0x00000020, 0xffffffff, 0),
Tony Lindgren1a542812020-05-07 09:43:08 -07001630 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000013, 0xffffffff, 0),
1631 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff, 0),
1632 /* Some timers on omap4 and later */
1633 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x50002100, 0xffffffff, 0),
1634 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x4fff1301, 0xffff00ff, 0),
1635 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000040, 0xffffffff, 0),
1636 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000011, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001637 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000060, 0xffffffff, 0),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001638 SYSC_QUIRK("tpcc", 0, 0, -ENODEV, -ENODEV, 0x40014c00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001639 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001640 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001641 SYSC_QUIRK("venc", 0x58003000, 0, -ENODEV, -ENODEV, 0x00000002, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001642 SYSC_QUIRK("vfpe", 0, 0, 0x104, -ENODEV, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001643#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001644};
1645
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001646/*
1647 * Early quirks based on module base and register offsets only that are
1648 * needed before the module revision can be read
1649 */
1650static void sysc_init_early_quirks(struct sysc *ddata)
1651{
1652 const struct sysc_revision_quirk *q;
1653 int i;
1654
1655 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1656 q = &sysc_revision_quirks[i];
1657
1658 if (!q->base)
1659 continue;
1660
1661 if (q->base != ddata->module_pa)
1662 continue;
1663
Tony Lindgren590e15c2020-02-24 12:58:03 -08001664 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001665 continue;
1666
Tony Lindgren590e15c2020-02-24 12:58:03 -08001667 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001668 continue;
1669
Tony Lindgren590e15c2020-02-24 12:58:03 -08001670 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001671 continue;
1672
1673 ddata->name = q->name;
1674 ddata->cfg.quirks |= q->quirks;
1675 }
1676}
1677
1678/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001679static void sysc_init_revision_quirks(struct sysc *ddata)
1680{
1681 const struct sysc_revision_quirk *q;
1682 int i;
1683
1684 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1685 q = &sysc_revision_quirks[i];
1686
1687 if (q->base && q->base != ddata->module_pa)
1688 continue;
1689
Tony Lindgren590e15c2020-02-24 12:58:03 -08001690 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001691 continue;
1692
Tony Lindgren590e15c2020-02-24 12:58:03 -08001693 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001694 continue;
1695
Tony Lindgren590e15c2020-02-24 12:58:03 -08001696 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001697 continue;
1698
1699 if (q->revision == ddata->revision ||
1700 (q->revision & q->revision_mask) ==
1701 (ddata->revision & q->revision_mask)) {
1702 ddata->name = q->name;
1703 ddata->cfg.quirks |= q->quirks;
1704 }
1705 }
1706}
1707
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001708/*
1709 * DSS needs dispc outputs disabled to reset modules. Returns mask of
1710 * enabled DSS interrupts. Eventually we may be able to do this on
1711 * dispc init rather than top-level DSS init.
1712 */
1713static u32 sysc_quirk_dispc(struct sysc *ddata, int dispc_offset,
1714 bool disable)
1715{
1716 bool lcd_en, digit_en, lcd2_en = false, lcd3_en = false;
1717 const int lcd_en_mask = BIT(0), digit_en_mask = BIT(1);
1718 int manager_count;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001719 bool framedonetv_irq = true;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001720 u32 val, irq_mask = 0;
1721
1722 switch (sysc_soc->soc) {
1723 case SOC_2420 ... SOC_3630:
1724 manager_count = 2;
1725 framedonetv_irq = false;
1726 break;
1727 case SOC_4430 ... SOC_4470:
1728 manager_count = 3;
1729 break;
1730 case SOC_5430:
1731 case SOC_DRA7:
1732 manager_count = 4;
1733 break;
1734 case SOC_AM4:
1735 manager_count = 1;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001736 framedonetv_irq = false;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001737 break;
1738 case SOC_UNKNOWN:
1739 default:
1740 return 0;
Yang Li52fbb5a2021-02-02 15:00:05 +08001741 }
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001742
1743 /* Remap the whole module range to be able to reset dispc outputs */
1744 devm_iounmap(ddata->dev, ddata->module_va);
1745 ddata->module_va = devm_ioremap(ddata->dev,
1746 ddata->module_pa,
1747 ddata->module_size);
1748 if (!ddata->module_va)
1749 return -EIO;
1750
1751 /* DISP_CONTROL */
1752 val = sysc_read(ddata, dispc_offset + 0x40);
1753 lcd_en = val & lcd_en_mask;
1754 digit_en = val & digit_en_mask;
1755 if (lcd_en)
1756 irq_mask |= BIT(0); /* FRAMEDONE */
1757 if (digit_en) {
1758 if (framedonetv_irq)
1759 irq_mask |= BIT(24); /* FRAMEDONETV */
1760 else
1761 irq_mask |= BIT(2) | BIT(3); /* EVSYNC bits */
1762 }
1763 if (disable & (lcd_en | digit_en))
1764 sysc_write(ddata, dispc_offset + 0x40,
1765 val & ~(lcd_en_mask | digit_en_mask));
1766
1767 if (manager_count <= 2)
1768 return irq_mask;
1769
1770 /* DISPC_CONTROL2 */
1771 val = sysc_read(ddata, dispc_offset + 0x238);
1772 lcd2_en = val & lcd_en_mask;
1773 if (lcd2_en)
1774 irq_mask |= BIT(22); /* FRAMEDONE2 */
1775 if (disable && lcd2_en)
1776 sysc_write(ddata, dispc_offset + 0x238,
1777 val & ~lcd_en_mask);
1778
1779 if (manager_count <= 3)
1780 return irq_mask;
1781
1782 /* DISPC_CONTROL3 */
1783 val = sysc_read(ddata, dispc_offset + 0x848);
1784 lcd3_en = val & lcd_en_mask;
1785 if (lcd3_en)
1786 irq_mask |= BIT(30); /* FRAMEDONE3 */
1787 if (disable && lcd3_en)
1788 sysc_write(ddata, dispc_offset + 0x848,
1789 val & ~lcd_en_mask);
1790
1791 return irq_mask;
1792}
1793
1794/* DSS needs child outputs disabled and SDI registers cleared for reset */
1795static void sysc_pre_reset_quirk_dss(struct sysc *ddata)
1796{
1797 const int dispc_offset = 0x1000;
1798 int error;
1799 u32 irq_mask, val;
1800
1801 /* Get enabled outputs */
1802 irq_mask = sysc_quirk_dispc(ddata, dispc_offset, false);
1803 if (!irq_mask)
1804 return;
1805
1806 /* Clear IRQSTATUS */
Tony Lindgren69e60902020-03-03 07:17:43 -08001807 sysc_write(ddata, dispc_offset + 0x18, irq_mask);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001808
1809 /* Disable outputs */
1810 val = sysc_quirk_dispc(ddata, dispc_offset, true);
1811
1812 /* Poll IRQSTATUS */
1813 error = readl_poll_timeout(ddata->module_va + dispc_offset + 0x18,
1814 val, val != irq_mask, 100, 50);
1815 if (error)
1816 dev_warn(ddata->dev, "%s: timed out %08x !+ %08x\n",
1817 __func__, val, irq_mask);
1818
1819 if (sysc_soc->soc == SOC_3430) {
1820 /* Clear DSS_SDI_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001821 sysc_write(ddata, 0x44, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001822
1823 /* Clear DSS_PLL_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001824 sysc_write(ddata, 0x48, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001825 }
1826
1827 /* Clear DSS_CONTROL to switch DSS clock sources to PRCM if not */
Tony Lindgren69e60902020-03-03 07:17:43 -08001828 sysc_write(ddata, 0x40, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001829}
1830
Tony Lindgren4e23be42019-06-10 04:48:05 -07001831/* 1-wire needs module's internal clocks enabled for reset */
Tony Lindgrenaec551c2020-02-24 12:58:03 -08001832static void sysc_pre_reset_quirk_hdq1w(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001833{
1834 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1835 u16 val;
1836
1837 val = sysc_read(ddata, offset);
1838 val |= BIT(5);
1839 sysc_write(ddata, offset, val);
1840}
1841
Tony Lindgren020003f2019-11-14 08:25:28 -08001842/* AESS (Audio Engine SubSystem) needs autogating set after enable */
1843static void sysc_module_enable_quirk_aess(struct sysc *ddata)
1844{
1845 int offset = 0x7c; /* AESS_AUTO_GATING_ENABLE */
1846
1847 sysc_write(ddata, offset, 1);
1848}
1849
Tony Lindgrene64c0212020-02-24 12:58:03 -08001850/* I2C needs to be disabled for reset */
Tony Lindgren4e23be42019-06-10 04:48:05 -07001851static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1852{
1853 int offset;
1854 u16 val;
1855
1856 /* I2C_CON, omap2/3 is different from omap4 and later */
1857 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1858 offset = 0x24;
1859 else
1860 offset = 0xa4;
1861
1862 /* I2C_EN */
1863 val = sysc_read(ddata, offset);
1864 if (enable)
1865 val |= BIT(15);
1866 else
1867 val &= ~BIT(15);
1868 sysc_write(ddata, offset, val);
1869}
1870
Tony Lindgrene64c0212020-02-24 12:58:03 -08001871static void sysc_pre_reset_quirk_i2c(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001872{
1873 sysc_clk_quirk_i2c(ddata, false);
1874}
1875
Tony Lindgrene64c0212020-02-24 12:58:03 -08001876static void sysc_post_reset_quirk_i2c(struct sysc *ddata)
1877{
1878 sysc_clk_quirk_i2c(ddata, true);
1879}
1880
Tony Lindgrene8639e12020-02-24 12:58:03 -08001881/* RTC on am3 and 4 needs to be unlocked and locked for sysconfig */
1882static void sysc_quirk_rtc(struct sysc *ddata, bool lock)
1883{
1884 u32 val, kick0_val = 0, kick1_val = 0;
1885 unsigned long flags;
1886 int error;
1887
1888 if (!lock) {
1889 kick0_val = 0x83e70b13;
1890 kick1_val = 0x95a4f1e0;
1891 }
1892
1893 local_irq_save(flags);
1894 /* RTC_STATUS BUSY bit may stay active for 1/32768 seconds (~30 usec) */
Tony Lindgrenafe6f1e2020-07-02 10:41:02 -07001895 error = readl_poll_timeout_atomic(ddata->module_va + 0x44, val,
1896 !(val & BIT(0)), 100, 50);
Tony Lindgrene8639e12020-02-24 12:58:03 -08001897 if (error)
1898 dev_warn(ddata->dev, "rtc busy timeout\n");
1899 /* Now we have ~15 microseconds to read/write various registers */
1900 sysc_write(ddata, 0x6c, kick0_val);
1901 sysc_write(ddata, 0x70, kick1_val);
1902 local_irq_restore(flags);
1903}
1904
1905static void sysc_module_unlock_quirk_rtc(struct sysc *ddata)
1906{
1907 sysc_quirk_rtc(ddata, false);
1908}
1909
1910static void sysc_module_lock_quirk_rtc(struct sysc *ddata)
1911{
1912 sysc_quirk_rtc(ddata, true);
1913}
1914
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001915/* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */
1916static void sysc_module_enable_quirk_sgx(struct sysc *ddata)
1917{
1918 int offset = 0xff08; /* OCP_DEBUG_CONFIG */
1919 u32 val = BIT(31); /* THALIA_INT_BYPASS */
1920
1921 sysc_write(ddata, offset, val);
1922}
1923
Tony Lindgren4e23be42019-06-10 04:48:05 -07001924/* Watchdog timer needs a disable sequence after reset */
1925static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1926{
1927 int wps, spr, error;
1928 u32 val;
1929
1930 wps = 0x34;
1931 spr = 0x48;
1932
1933 sysc_write(ddata, spr, 0xaaaa);
1934 error = readl_poll_timeout(ddata->module_va + wps, val,
1935 !(val & 0x10), 100,
1936 MAX_MODULE_SOFTRESET_WAIT);
1937 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001938 dev_warn(ddata->dev, "wdt disable step1 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001939
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001940 sysc_write(ddata, spr, 0x5555);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001941 error = readl_poll_timeout(ddata->module_va + wps, val,
1942 !(val & 0x10), 100,
1943 MAX_MODULE_SOFTRESET_WAIT);
1944 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001945 dev_warn(ddata->dev, "wdt disable step2 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001946}
1947
Suman Annab2745d92020-02-27 16:28:34 -06001948/* PRUSS needs to set MSTANDBY_INIT inorder to idle properly */
1949static void sysc_module_disable_quirk_pruss(struct sysc *ddata)
1950{
1951 u32 reg;
1952
1953 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1954 reg |= SYSC_PRUSS_STANDBY_INIT;
1955 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
1956}
1957
Tony Lindgren4e23be42019-06-10 04:48:05 -07001958static void sysc_init_module_quirks(struct sysc *ddata)
1959{
1960 if (ddata->legacy_mode || !ddata->name)
1961 return;
1962
1963 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08001964 ddata->pre_reset_quirk = sysc_pre_reset_quirk_hdq1w;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001965
1966 return;
1967 }
1968
Tony Lindgrencfeeea62020-11-16 12:57:13 +02001969#ifdef CONFIG_OMAP_GPMC_DEBUG
1970 if (ddata->cfg.quirks & SYSC_QUIRK_GPMC_DEBUG) {
1971 ddata->cfg.quirks |= SYSC_QUIRK_NO_RESET_ON_INIT;
1972
1973 return;
1974 }
1975#endif
1976
Tony Lindgren4e23be42019-06-10 04:48:05 -07001977 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08001978 ddata->pre_reset_quirk = sysc_pre_reset_quirk_i2c;
1979 ddata->post_reset_quirk = sysc_post_reset_quirk_i2c;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001980
1981 return;
1982 }
1983
Tony Lindgren020003f2019-11-14 08:25:28 -08001984 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_AESS)
1985 ddata->module_enable_quirk = sysc_module_enable_quirk_aess;
1986
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001987 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_DSS_RESET)
1988 ddata->pre_reset_quirk = sysc_pre_reset_quirk_dss;
1989
Tony Lindgrene8639e12020-02-24 12:58:03 -08001990 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_RTC_UNLOCK) {
1991 ddata->module_unlock_quirk = sysc_module_unlock_quirk_rtc;
1992 ddata->module_lock_quirk = sysc_module_lock_quirk_rtc;
1993
1994 return;
1995 }
1996
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001997 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_SGX)
1998 ddata->module_enable_quirk = sysc_module_enable_quirk_sgx;
1999
Tony Lindgrenc7d86692019-10-17 11:21:44 -07002000 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT) {
Tony Lindgren4e23be42019-06-10 04:48:05 -07002001 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
Tony Lindgrenc7d86692019-10-17 11:21:44 -07002002 ddata->module_disable_quirk = sysc_reset_done_quirk_wdt;
2003 }
Suman Annab2745d92020-02-27 16:28:34 -06002004
2005 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_PRUSS)
2006 ddata->module_disable_quirk = sysc_module_disable_quirk_pruss;
Tony Lindgren4e23be42019-06-10 04:48:05 -07002007}
2008
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002009static int sysc_clockdomain_init(struct sysc *ddata)
2010{
2011 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2012 struct clk *fck = NULL, *ick = NULL;
2013 int error;
2014
2015 if (!pdata || !pdata->init_clockdomain)
2016 return 0;
2017
2018 switch (ddata->nr_clocks) {
2019 case 2:
2020 ick = ddata->clocks[SYSC_ICK];
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002021 fallthrough;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002022 case 1:
2023 fck = ddata->clocks[SYSC_FCK];
2024 break;
2025 case 0:
2026 return 0;
2027 }
2028
2029 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
2030 if (!error || error == -ENODEV)
2031 return 0;
2032
2033 return error;
2034}
2035
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002036/*
2037 * Note that pdata->init_module() typically does a reset first. After
2038 * pdata->init_module() is done, PM runtime can be used for the interconnect
2039 * target module.
2040 */
2041static int sysc_legacy_init(struct sysc *ddata)
2042{
2043 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2044 int error;
2045
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002046 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002047 return 0;
2048
2049 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
2050 if (error == -EEXIST)
2051 error = 0;
2052
2053 return error;
2054}
2055
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002056/*
2057 * Note that the caller must ensure the interconnect target module is enabled
2058 * before calling reset. Otherwise reset will not complete.
2059 */
Faiz Abbas596e7952018-07-09 22:18:39 +05302060static int sysc_reset(struct sysc *ddata)
2061{
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002062 int sysc_offset, sysc_val, error;
2063 u32 sysc_mask;
Faiz Abbas596e7952018-07-09 22:18:39 +05302064
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002065 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002066
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002067 if (ddata->legacy_mode ||
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002068 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05302069 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
2070 return 0;
2071
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002072 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05302073
Tony Lindgrene64c0212020-02-24 12:58:03 -08002074 if (ddata->pre_reset_quirk)
2075 ddata->pre_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002076
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002077 if (sysc_offset >= 0) {
2078 sysc_val = sysc_read_sysconfig(ddata);
2079 sysc_val |= sysc_mask;
2080 sysc_write(ddata, sysc_offset, sysc_val);
2081 }
Faiz Abbas596e7952018-07-09 22:18:39 +05302082
Tony Lindgrene709ed72019-12-12 08:20:10 -08002083 if (ddata->cfg.srst_udelay)
2084 usleep_range(ddata->cfg.srst_udelay,
2085 ddata->cfg.srst_udelay * 2);
2086
Tony Lindgrene64c0212020-02-24 12:58:03 -08002087 if (ddata->post_reset_quirk)
2088 ddata->post_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002089
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002090 error = sysc_wait_softreset(ddata);
2091 if (error)
2092 dev_warn(ddata->dev, "OCP softreset timed out\n");
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002093
Tony Lindgren4e23be42019-06-10 04:48:05 -07002094 if (ddata->reset_done_quirk)
2095 ddata->reset_done_quirk(ddata);
2096
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002097 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05302098}
2099
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002100/*
2101 * At this point the module is configured enough to read the revision but
2102 * module may not be completely configured yet to use PM runtime. Enable
2103 * all clocks directly during init to configure the quirks needed for PM
2104 * runtime based on the revision register.
2105 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08002106static int sysc_init_module(struct sysc *ddata)
2107{
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002108 bool rstctrl_deasserted = false;
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002109 int error = 0;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002110
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002111 error = sysc_clockdomain_init(ddata);
2112 if (error)
2113 return error;
2114
Tony Lindgrend0989132019-09-05 07:37:22 -07002115 sysc_clkdm_deny_idle(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002116
Tony Lindgrend0989132019-09-05 07:37:22 -07002117 /*
2118 * Always enable clocks. The bootloader may or may not have enabled
2119 * the related clocks.
2120 */
2121 error = sysc_enable_opt_clocks(ddata);
2122 if (error)
2123 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002124
Tony Lindgrend0989132019-09-05 07:37:22 -07002125 error = sysc_enable_main_clocks(ddata);
2126 if (error)
2127 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05302128
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002129 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
Tero Kristodf4f3452019-10-07 15:29:30 +03002130 error = reset_control_deassert(ddata->rsts);
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002131 if (error)
2132 goto err_main_clocks;
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002133 rstctrl_deasserted = true;
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002134 }
2135
Tony Lindgren566a9b052017-12-15 09:41:19 -08002136 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002137 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002138 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002139
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002140 if (ddata->legacy_mode) {
2141 error = sysc_legacy_init(ddata);
2142 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002143 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002144 }
2145
Tony Lindgrend0989132019-09-05 07:37:22 -07002146 if (!ddata->legacy_mode) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002147 error = sysc_enable_module(ddata->dev);
2148 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002149 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002150 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002151
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002152 error = sysc_reset(ddata);
2153 if (error)
2154 dev_err(ddata->dev, "Reset failed with %d\n", error);
2155
Tero Kristocdc56c12019-10-07 15:29:31 +03002156 if (error && !ddata->legacy_mode)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002157 sysc_disable_module(ddata->dev);
2158
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002159err_main_clocks:
Tero Kristocdc56c12019-10-07 15:29:31 +03002160 if (error)
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002161 sysc_disable_main_clocks(ddata);
2162err_opt_clocks:
Tony Lindgrend0989132019-09-05 07:37:22 -07002163 /* No re-enable of clockdomain autoidle to prevent module autoidle */
Tero Kristocdc56c12019-10-07 15:29:31 +03002164 if (error) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002165 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002166 sysc_clkdm_allow_idle(ddata);
2167 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002168
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002169 if (error && rstctrl_deasserted &&
2170 !(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
2171 reset_control_assert(ddata->rsts);
2172
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002173 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002174}
2175
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002176static int sysc_init_sysc_mask(struct sysc *ddata)
2177{
2178 struct device_node *np = ddata->dev->of_node;
2179 int error;
2180 u32 val;
2181
2182 error = of_property_read_u32(np, "ti,sysc-mask", &val);
2183 if (error)
2184 return 0;
2185
Tony Lindgrene212abd2019-07-22 03:44:52 -07002186 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002187
2188 return 0;
2189}
2190
2191static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
2192 const char *name)
2193{
2194 struct device_node *np = ddata->dev->of_node;
2195 struct property *prop;
2196 const __be32 *p;
2197 u32 val;
2198
2199 of_property_for_each_u32(np, name, prop, p, val) {
2200 if (val >= SYSC_NR_IDLEMODES) {
2201 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
2202 return -EINVAL;
2203 }
2204 *idlemodes |= (1 << val);
2205 }
2206
2207 return 0;
2208}
2209
2210static int sysc_init_idlemodes(struct sysc *ddata)
2211{
2212 int error;
2213
2214 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
2215 "ti,sysc-midle");
2216 if (error)
2217 return error;
2218
2219 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
2220 "ti,sysc-sidle");
2221 if (error)
2222 return error;
2223
2224 return 0;
2225}
2226
2227/*
2228 * Only some devices on omap4 and later have SYSCONFIG reset done
2229 * bit. We can detect this if there is no SYSSTATUS at all, or the
2230 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
2231 * have multiple bits for the child devices like OHCI and EHCI.
2232 * Depends on SYSC being parsed first.
2233 */
2234static int sysc_init_syss_mask(struct sysc *ddata)
2235{
2236 struct device_node *np = ddata->dev->of_node;
2237 int error;
2238 u32 val;
2239
2240 error = of_property_read_u32(np, "ti,syss-mask", &val);
2241 if (error) {
2242 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
2243 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
2244 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2245 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2246
2247 return 0;
2248 }
2249
2250 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2251 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2252
2253 ddata->cfg.syss_mask = val;
2254
2255 return 0;
2256}
2257
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002258/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002259 * Many child device drivers need to have fck and opt clocks available
2260 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002261 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002262static int sysc_child_add_named_clock(struct sysc *ddata,
2263 struct device *child,
2264 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002265{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002266 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002267 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002268 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002269
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002270 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002271 return 0;
2272
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002273 clk = clk_get(child, name);
2274 if (!IS_ERR(clk)) {
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002275 error = -EEXIST;
2276 goto put_clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002277 }
2278
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002279 clk = clk_get(ddata->dev, name);
2280 if (IS_ERR(clk))
2281 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002282
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002283 l = clkdev_create(clk, name, dev_name(child));
2284 if (!l)
2285 error = -ENOMEM;
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002286put_clk:
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002287 clk_put(clk);
2288
2289 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002290}
2291
Tony Lindgren09dfe582018-04-16 10:25:52 -07002292static int sysc_child_add_clocks(struct sysc *ddata,
2293 struct device *child)
2294{
2295 int i, error;
2296
2297 for (i = 0; i < ddata->nr_clocks; i++) {
2298 error = sysc_child_add_named_clock(ddata,
2299 child,
2300 ddata->clock_roles[i]);
2301 if (error && error != -EEXIST) {
2302 dev_err(ddata->dev, "could not add child clock %s: %i\n",
2303 ddata->clock_roles[i], error);
2304
2305 return error;
2306 }
2307 }
2308
2309 return 0;
2310}
2311
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002312static struct device_type sysc_device_type = {
2313};
2314
2315static struct sysc *sysc_child_to_parent(struct device *dev)
2316{
2317 struct device *parent = dev->parent;
2318
2319 if (!parent || parent->type != &sysc_device_type)
2320 return NULL;
2321
2322 return dev_get_drvdata(parent);
2323}
2324
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002325static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
2326{
2327 struct sysc *ddata;
2328 int error;
2329
2330 ddata = sysc_child_to_parent(dev);
2331
2332 error = pm_generic_runtime_suspend(dev);
2333 if (error)
2334 return error;
2335
2336 if (!ddata->enabled)
2337 return 0;
2338
2339 return sysc_runtime_suspend(ddata->dev);
2340}
2341
2342static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
2343{
2344 struct sysc *ddata;
2345 int error;
2346
2347 ddata = sysc_child_to_parent(dev);
2348
2349 if (!ddata->enabled) {
2350 error = sysc_runtime_resume(ddata->dev);
2351 if (error < 0)
2352 dev_err(ddata->dev,
2353 "%s error: %i\n", __func__, error);
2354 }
2355
2356 return pm_generic_runtime_resume(dev);
2357}
2358
2359#ifdef CONFIG_PM_SLEEP
2360static int sysc_child_suspend_noirq(struct device *dev)
2361{
2362 struct sysc *ddata;
2363 int error;
2364
2365 ddata = sysc_child_to_parent(dev);
2366
Tony Lindgrenef55f822018-04-16 10:27:15 -07002367 dev_dbg(ddata->dev, "%s %s\n", __func__,
2368 ddata->name ? ddata->name : "");
2369
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002370 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002371 if (error) {
2372 dev_err(dev, "%s error at %i: %i\n",
2373 __func__, __LINE__, error);
2374
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002375 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002376 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002377
2378 if (!pm_runtime_status_suspended(dev)) {
2379 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002380 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07002381 dev_dbg(dev, "%s busy at %i: %i\n",
2382 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002383
Tony Lindgren4f3530f2018-08-08 01:07:06 -07002384 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002385 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002386
2387 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002388 if (error) {
2389 dev_err(dev, "%s error at %i: %i\n",
2390 __func__, __LINE__, error);
2391
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002392 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002393 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002394
2395 ddata->child_needs_resume = true;
2396 }
2397
2398 return 0;
2399}
2400
2401static int sysc_child_resume_noirq(struct device *dev)
2402{
2403 struct sysc *ddata;
2404 int error;
2405
2406 ddata = sysc_child_to_parent(dev);
2407
Tony Lindgrenef55f822018-04-16 10:27:15 -07002408 dev_dbg(ddata->dev, "%s %s\n", __func__,
2409 ddata->name ? ddata->name : "");
2410
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002411 if (ddata->child_needs_resume) {
2412 ddata->child_needs_resume = false;
2413
2414 error = sysc_runtime_resume(ddata->dev);
2415 if (error)
2416 dev_err(ddata->dev,
2417 "%s runtime resume error: %i\n",
2418 __func__, error);
2419
2420 error = pm_generic_runtime_resume(dev);
2421 if (error)
2422 dev_err(ddata->dev,
2423 "%s generic runtime resume: %i\n",
2424 __func__, error);
2425 }
2426
2427 return pm_generic_resume_noirq(dev);
2428}
2429#endif
2430
Tony Lindgrenb7182b42019-03-21 11:00:21 -07002431static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002432 .ops = {
2433 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
2434 sysc_child_runtime_resume,
2435 NULL)
2436 USE_PLATFORM_PM_SLEEP_OPS
2437 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
2438 sysc_child_resume_noirq)
2439 }
2440};
2441
2442/**
2443 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
2444 * @ddata: device driver data
2445 * @child: child device driver
2446 *
2447 * Allow idle for child devices as done with _od_runtime_suspend().
2448 * Otherwise many child devices will not idle because of the permanent
2449 * parent usecount set in pm_runtime_irq_safe().
2450 *
2451 * Note that the long term solution is to just modify the child device
2452 * drivers to not set pm_runtime_irq_safe() and then this can be just
2453 * dropped.
2454 */
2455static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
2456{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002457 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
2458 dev_pm_domain_set(child, &sysc_child_pm_domain);
2459}
2460
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002461static int sysc_notifier_call(struct notifier_block *nb,
2462 unsigned long event, void *device)
2463{
2464 struct device *dev = device;
2465 struct sysc *ddata;
2466 int error;
2467
2468 ddata = sysc_child_to_parent(dev);
2469 if (!ddata)
2470 return NOTIFY_DONE;
2471
2472 switch (event) {
2473 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07002474 error = sysc_child_add_clocks(ddata, dev);
2475 if (error)
2476 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002477 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002478 break;
2479 default:
2480 break;
2481 }
2482
2483 return NOTIFY_DONE;
2484}
2485
2486static struct notifier_block sysc_nb = {
2487 .notifier_call = sysc_notifier_call,
2488};
2489
Tony Lindgren566a9b052017-12-15 09:41:19 -08002490/* Device tree configured quirks */
2491struct sysc_dts_quirk {
2492 const char *name;
2493 u32 mask;
2494};
2495
2496static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2497 { .name = "ti,no-idle-on-init",
2498 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2499 { .name = "ti,no-reset-on-init",
2500 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002501 { .name = "ti,no-idle",
2502 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002503};
2504
Tony Lindgren4014c082018-12-10 14:11:26 -08002505static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2506 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002507{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002508 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002509 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002510
2511 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002512 const char *name = sysc_dts_quirks[i].name;
2513
2514 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002515 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002516 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002517
2518 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002519 if (is_child) {
2520 dev_warn(ddata->dev,
2521 "dts flag should be at module level for %s\n",
2522 name);
2523 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002524 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002525}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002526
Tony Lindgren4014c082018-12-10 14:11:26 -08002527static int sysc_init_dts_quirks(struct sysc *ddata)
2528{
2529 struct device_node *np = ddata->dev->of_node;
2530 int error;
2531 u32 val;
2532
2533 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2534
2535 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002536 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2537 if (!error) {
2538 if (val > 255) {
2539 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2540 val);
2541 }
2542
2543 ddata->cfg.srst_udelay = (u8)val;
2544 }
2545
2546 return 0;
2547}
2548
Tony Lindgren0eecc632017-10-10 14:23:43 -07002549static void sysc_unprepare(struct sysc *ddata)
2550{
2551 int i;
2552
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002553 if (!ddata->clocks)
2554 return;
2555
Tony Lindgren0eecc632017-10-10 14:23:43 -07002556 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2557 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2558 clk_unprepare(ddata->clocks[i]);
2559 }
2560}
2561
Tony Lindgren70a65242017-12-15 09:41:09 -08002562/*
2563 * Common sysc register bits found on omap2, also known as type1
2564 */
2565static const struct sysc_regbits sysc_regbits_omap2 = {
2566 .dmadisable_shift = -ENODEV,
2567 .midle_shift = 12,
2568 .sidle_shift = 3,
2569 .clkact_shift = 8,
2570 .emufree_shift = 5,
2571 .enwkup_shift = 2,
2572 .srst_shift = 1,
2573 .autoidle_shift = 0,
2574};
2575
2576static const struct sysc_capabilities sysc_omap2 = {
2577 .type = TI_SYSC_OMAP2,
2578 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2579 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2580 SYSC_OMAP2_AUTOIDLE,
2581 .regbits = &sysc_regbits_omap2,
2582};
2583
2584/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2585static const struct sysc_capabilities sysc_omap2_timer = {
2586 .type = TI_SYSC_OMAP2_TIMER,
2587 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2588 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2589 SYSC_OMAP2_AUTOIDLE,
2590 .regbits = &sysc_regbits_omap2,
2591 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2592};
2593
2594/*
2595 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2596 * with different sidle position
2597 */
2598static const struct sysc_regbits sysc_regbits_omap3_sham = {
2599 .dmadisable_shift = -ENODEV,
2600 .midle_shift = -ENODEV,
2601 .sidle_shift = 4,
2602 .clkact_shift = -ENODEV,
2603 .enwkup_shift = -ENODEV,
2604 .srst_shift = 1,
2605 .autoidle_shift = 0,
2606 .emufree_shift = -ENODEV,
2607};
2608
2609static const struct sysc_capabilities sysc_omap3_sham = {
2610 .type = TI_SYSC_OMAP3_SHAM,
2611 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2612 .regbits = &sysc_regbits_omap3_sham,
2613};
2614
2615/*
2616 * AES register bits found on omap3 and later, a variant of
2617 * sysc_regbits_omap2 with different sidle position
2618 */
2619static const struct sysc_regbits sysc_regbits_omap3_aes = {
2620 .dmadisable_shift = -ENODEV,
2621 .midle_shift = -ENODEV,
2622 .sidle_shift = 6,
2623 .clkact_shift = -ENODEV,
2624 .enwkup_shift = -ENODEV,
2625 .srst_shift = 1,
2626 .autoidle_shift = 0,
2627 .emufree_shift = -ENODEV,
2628};
2629
2630static const struct sysc_capabilities sysc_omap3_aes = {
2631 .type = TI_SYSC_OMAP3_AES,
2632 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2633 .regbits = &sysc_regbits_omap3_aes,
2634};
2635
2636/*
2637 * Common sysc register bits found on omap4, also known as type2
2638 */
2639static const struct sysc_regbits sysc_regbits_omap4 = {
2640 .dmadisable_shift = 16,
2641 .midle_shift = 4,
2642 .sidle_shift = 2,
2643 .clkact_shift = -ENODEV,
2644 .enwkup_shift = -ENODEV,
2645 .emufree_shift = 1,
2646 .srst_shift = 0,
2647 .autoidle_shift = -ENODEV,
2648};
2649
2650static const struct sysc_capabilities sysc_omap4 = {
2651 .type = TI_SYSC_OMAP4,
2652 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2653 SYSC_OMAP4_SOFTRESET,
2654 .regbits = &sysc_regbits_omap4,
2655};
2656
2657static const struct sysc_capabilities sysc_omap4_timer = {
2658 .type = TI_SYSC_OMAP4_TIMER,
2659 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2660 SYSC_OMAP4_SOFTRESET,
2661 .regbits = &sysc_regbits_omap4,
2662};
2663
2664/*
2665 * Common sysc register bits found on omap4, also known as type3
2666 */
2667static const struct sysc_regbits sysc_regbits_omap4_simple = {
2668 .dmadisable_shift = -ENODEV,
2669 .midle_shift = 2,
2670 .sidle_shift = 0,
2671 .clkact_shift = -ENODEV,
2672 .enwkup_shift = -ENODEV,
2673 .srst_shift = -ENODEV,
2674 .emufree_shift = -ENODEV,
2675 .autoidle_shift = -ENODEV,
2676};
2677
2678static const struct sysc_capabilities sysc_omap4_simple = {
2679 .type = TI_SYSC_OMAP4_SIMPLE,
2680 .regbits = &sysc_regbits_omap4_simple,
2681};
2682
2683/*
2684 * SmartReflex sysc found on omap34xx
2685 */
2686static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2687 .dmadisable_shift = -ENODEV,
2688 .midle_shift = -ENODEV,
2689 .sidle_shift = -ENODEV,
2690 .clkact_shift = 20,
2691 .enwkup_shift = -ENODEV,
2692 .srst_shift = -ENODEV,
2693 .emufree_shift = -ENODEV,
2694 .autoidle_shift = -ENODEV,
2695};
2696
2697static const struct sysc_capabilities sysc_34xx_sr = {
2698 .type = TI_SYSC_OMAP34XX_SR,
2699 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2700 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002701 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2702 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002703};
2704
2705/*
2706 * SmartReflex sysc found on omap36xx and later
2707 */
2708static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2709 .dmadisable_shift = -ENODEV,
2710 .midle_shift = -ENODEV,
2711 .sidle_shift = 24,
2712 .clkact_shift = -ENODEV,
2713 .enwkup_shift = 26,
2714 .srst_shift = -ENODEV,
2715 .emufree_shift = -ENODEV,
2716 .autoidle_shift = -ENODEV,
2717};
2718
2719static const struct sysc_capabilities sysc_36xx_sr = {
2720 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002721 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002722 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002723 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002724};
2725
2726static const struct sysc_capabilities sysc_omap4_sr = {
2727 .type = TI_SYSC_OMAP4_SR,
2728 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002729 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002730};
2731
2732/*
2733 * McASP register bits found on omap4 and later
2734 */
2735static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2736 .dmadisable_shift = -ENODEV,
2737 .midle_shift = -ENODEV,
2738 .sidle_shift = 0,
2739 .clkact_shift = -ENODEV,
2740 .enwkup_shift = -ENODEV,
2741 .srst_shift = -ENODEV,
2742 .emufree_shift = -ENODEV,
2743 .autoidle_shift = -ENODEV,
2744};
2745
2746static const struct sysc_capabilities sysc_omap4_mcasp = {
2747 .type = TI_SYSC_OMAP4_MCASP,
2748 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002749 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2750};
2751
2752/*
2753 * McASP found on dra7 and later
2754 */
2755static const struct sysc_capabilities sysc_dra7_mcasp = {
2756 .type = TI_SYSC_OMAP4_SIMPLE,
2757 .regbits = &sysc_regbits_omap4_simple,
2758 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002759};
2760
2761/*
2762 * FS USB host found on omap4 and later
2763 */
2764static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2765 .dmadisable_shift = -ENODEV,
2766 .midle_shift = -ENODEV,
2767 .sidle_shift = 24,
2768 .clkact_shift = -ENODEV,
2769 .enwkup_shift = 26,
2770 .srst_shift = -ENODEV,
2771 .emufree_shift = -ENODEV,
2772 .autoidle_shift = -ENODEV,
2773};
2774
2775static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2776 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2777 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2778 .regbits = &sysc_regbits_omap4_usb_host_fs,
2779};
2780
Faiz Abbas7f35e632018-07-09 22:18:38 +05302781static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2782 .dmadisable_shift = -ENODEV,
2783 .midle_shift = -ENODEV,
2784 .sidle_shift = -ENODEV,
2785 .clkact_shift = -ENODEV,
2786 .enwkup_shift = 4,
2787 .srst_shift = 0,
2788 .emufree_shift = -ENODEV,
2789 .autoidle_shift = -ENODEV,
2790};
2791
2792static const struct sysc_capabilities sysc_dra7_mcan = {
2793 .type = TI_SYSC_DRA7_MCAN,
2794 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2795 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002796 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302797};
2798
Suman Annab2745d92020-02-27 16:28:34 -06002799/*
2800 * PRUSS found on some AM33xx, AM437x and AM57xx SoCs
2801 */
2802static const struct sysc_capabilities sysc_pruss = {
2803 .type = TI_SYSC_PRUSS,
2804 .sysc_mask = SYSC_PRUSS_STANDBY_INIT | SYSC_PRUSS_SUB_MWAIT,
2805 .regbits = &sysc_regbits_omap4_simple,
2806 .mod_quirks = SYSC_MODULE_QUIRK_PRUSS,
2807};
2808
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002809static int sysc_init_pdata(struct sysc *ddata)
2810{
2811 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002812 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002813
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002814 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002815 return 0;
2816
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002817 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2818 if (!mdata)
2819 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002820
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002821 if (ddata->legacy_mode) {
2822 mdata->name = ddata->legacy_mode;
2823 mdata->module_pa = ddata->module_pa;
2824 mdata->module_size = ddata->module_size;
2825 mdata->offsets = ddata->offsets;
2826 mdata->nr_offsets = SYSC_MAX_REGS;
2827 mdata->cap = ddata->cap;
2828 mdata->cfg = &ddata->cfg;
2829 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002830
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002831 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002832
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002833 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002834}
2835
Tony Lindgren70a65242017-12-15 09:41:09 -08002836static int sysc_init_match(struct sysc *ddata)
2837{
2838 const struct sysc_capabilities *cap;
2839
2840 cap = of_device_get_match_data(ddata->dev);
2841 if (!cap)
2842 return -EINVAL;
2843
2844 ddata->cap = cap;
2845 if (ddata->cap)
2846 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2847
2848 return 0;
2849}
2850
Tony Lindgren76f0f772018-02-23 08:28:45 -08002851static void ti_sysc_idle(struct work_struct *work)
2852{
2853 struct sysc *ddata;
2854
2855 ddata = container_of(work, struct sysc, idle_work.work);
2856
Tony Lindgrend0989132019-09-05 07:37:22 -07002857 /*
2858 * One time decrement of clock usage counts if left on from init.
2859 * Note that we disable opt clocks unconditionally in this case
2860 * as they are enabled unconditionally during init without
2861 * considering sysc_opt_clks_needed() at that point.
2862 */
2863 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2864 SYSC_QUIRK_NO_IDLE_ON_INIT)) {
Tony Lindgrend0989132019-09-05 07:37:22 -07002865 sysc_disable_main_clocks(ddata);
2866 sysc_disable_opt_clocks(ddata);
2867 sysc_clkdm_allow_idle(ddata);
2868 }
2869
2870 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
2871 if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE)
2872 return;
2873
2874 /*
2875 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
2876 * and SYSC_QUIRK_NO_RESET_ON_INIT
2877 */
Tony Lindgren76f0f772018-02-23 08:28:45 -08002878 if (pm_runtime_active(ddata->dev))
2879 pm_runtime_put_sync(ddata->dev);
2880}
2881
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002882/*
2883 * SoC model and features detection. Only needed for SoCs that need
2884 * special handling for quirks, no need to list others.
2885 */
2886static const struct soc_device_attribute sysc_soc_match[] = {
2887 SOC_FLAG("OMAP242*", SOC_2420),
2888 SOC_FLAG("OMAP243*", SOC_2430),
2889 SOC_FLAG("OMAP3[45]*", SOC_3430),
2890 SOC_FLAG("OMAP3[67]*", SOC_3630),
2891 SOC_FLAG("OMAP443*", SOC_4430),
2892 SOC_FLAG("OMAP446*", SOC_4460),
2893 SOC_FLAG("OMAP447*", SOC_4470),
2894 SOC_FLAG("OMAP54*", SOC_5430),
2895 SOC_FLAG("AM433", SOC_AM3),
2896 SOC_FLAG("AM43*", SOC_AM4),
2897 SOC_FLAG("DRA7*", SOC_DRA7),
2898
2899 { /* sentinel */ },
2900};
2901
2902/*
2903 * List of SoCs variants with disabled features. By default we assume all
2904 * devices in the device tree are available so no need to list those SoCs.
2905 */
2906static const struct soc_device_attribute sysc_soc_feat_match[] = {
2907 /* OMAP3430/3530 and AM3517 variants with some accelerators disabled */
2908 SOC_FLAG("AM3505", DIS_SGX),
2909 SOC_FLAG("OMAP3525", DIS_SGX),
2910 SOC_FLAG("OMAP3515", DIS_IVA | DIS_SGX),
2911 SOC_FLAG("OMAP3503", DIS_ISP | DIS_IVA | DIS_SGX),
2912
2913 /* OMAP3630/DM3730 variants with some accelerators disabled */
2914 SOC_FLAG("AM3703", DIS_IVA | DIS_SGX),
2915 SOC_FLAG("DM3725", DIS_SGX),
2916 SOC_FLAG("OMAP3611", DIS_ISP | DIS_IVA | DIS_SGX),
2917 SOC_FLAG("OMAP3615/AM3715", DIS_IVA),
2918 SOC_FLAG("OMAP3621", DIS_ISP),
2919
2920 { /* sentinel */ },
2921};
2922
2923static int sysc_add_disabled(unsigned long base)
2924{
2925 struct sysc_address *disabled_module;
2926
2927 disabled_module = kzalloc(sizeof(*disabled_module), GFP_KERNEL);
2928 if (!disabled_module)
2929 return -ENOMEM;
2930
2931 disabled_module->base = base;
2932
2933 mutex_lock(&sysc_soc->list_lock);
2934 list_add(&disabled_module->node, &sysc_soc->disabled_modules);
2935 mutex_unlock(&sysc_soc->list_lock);
2936
2937 return 0;
2938}
2939
2940/*
2941 * One time init to detect the booted SoC and disable unavailable features.
2942 * Note that we initialize static data shared across all ti-sysc instances
2943 * so ddata is only used for SoC type. This can be called from module_init
2944 * once we no longer need to rely on platform data.
2945 */
2946static int sysc_init_soc(struct sysc *ddata)
2947{
2948 const struct soc_device_attribute *match;
2949 struct ti_sysc_platform_data *pdata;
2950 unsigned long features = 0;
Tony Lindgren5f7259a2021-03-08 11:35:09 +02002951 struct device_node *np;
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002952
2953 if (sysc_soc)
2954 return 0;
2955
2956 sysc_soc = kzalloc(sizeof(*sysc_soc), GFP_KERNEL);
2957 if (!sysc_soc)
2958 return -ENOMEM;
2959
2960 mutex_init(&sysc_soc->list_lock);
2961 INIT_LIST_HEAD(&sysc_soc->disabled_modules);
2962 sysc_soc->general_purpose = true;
2963
2964 pdata = dev_get_platdata(ddata->dev);
2965 if (pdata && pdata->soc_type_gp)
2966 sysc_soc->general_purpose = pdata->soc_type_gp();
2967
2968 match = soc_device_match(sysc_soc_match);
2969 if (match && match->data)
2970 sysc_soc->soc = (int)match->data;
2971
Tony Lindgren5f7259a2021-03-08 11:35:09 +02002972 /*
2973 * Check and warn about possible old incomplete dtb. We now want to see
2974 * simple-pm-bus instead of simple-bus in the dtb for genpd using SoCs.
2975 */
2976 switch (sysc_soc->soc) {
2977 case SOC_AM3:
2978 case SOC_AM4:
Tony Lindgren4adcf4c2021-03-12 10:23:48 +02002979 case SOC_4430 ... SOC_4470:
2980 case SOC_5430:
2981 case SOC_DRA7:
Tony Lindgren5f7259a2021-03-08 11:35:09 +02002982 np = of_find_node_by_path("/ocp");
2983 WARN_ONCE(np && of_device_is_compatible(np, "simple-bus"),
2984 "ti-sysc: Incomplete old dtb, please update\n");
2985 break;
2986 default:
2987 break;
2988 }
2989
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07002990 /* Ignore devices that are not available on HS and EMU SoCs */
2991 if (!sysc_soc->general_purpose) {
2992 switch (sysc_soc->soc) {
2993 case SOC_3430 ... SOC_3630:
2994 sysc_add_disabled(0x48304000); /* timer12 */
2995 break;
Kevin Hilmana6d90e92021-07-20 11:27:16 -07002996 case SOC_AM3:
2997 sysc_add_disabled(0x48310000); /* rng */
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07002998 default:
2999 break;
Yang Li52fbb5a2021-02-02 15:00:05 +08003000 }
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07003001 }
3002
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003003 match = soc_device_match(sysc_soc_feat_match);
3004 if (!match)
3005 return 0;
3006
3007 if (match->data)
3008 features = (unsigned long)match->data;
3009
3010 /*
3011 * Add disabled devices to the list based on the module base.
3012 * Note that this must be done before we attempt to access the
3013 * device and have module revision checks working.
3014 */
3015 if (features & DIS_ISP)
3016 sysc_add_disabled(0x480bd400);
3017 if (features & DIS_IVA)
3018 sysc_add_disabled(0x5d000000);
3019 if (features & DIS_SGX)
3020 sysc_add_disabled(0x50000000);
3021
3022 return 0;
3023}
3024
3025static void sysc_cleanup_soc(void)
3026{
3027 struct sysc_address *disabled_module;
3028 struct list_head *pos, *tmp;
3029
3030 if (!sysc_soc)
3031 return;
3032
3033 mutex_lock(&sysc_soc->list_lock);
3034 list_for_each_safe(pos, tmp, &sysc_soc->disabled_modules) {
3035 disabled_module = list_entry(pos, struct sysc_address, node);
3036 list_del(pos);
3037 kfree(disabled_module);
3038 }
3039 mutex_unlock(&sysc_soc->list_lock);
3040}
3041
3042static int sysc_check_disabled_devices(struct sysc *ddata)
3043{
3044 struct sysc_address *disabled_module;
3045 struct list_head *pos;
3046 int error = 0;
3047
3048 mutex_lock(&sysc_soc->list_lock);
3049 list_for_each(pos, &sysc_soc->disabled_modules) {
3050 disabled_module = list_entry(pos, struct sysc_address, node);
3051 if (ddata->module_pa == disabled_module->base) {
3052 dev_dbg(ddata->dev, "module disabled for this SoC\n");
3053 error = -ENODEV;
3054 break;
3055 }
3056 }
3057 mutex_unlock(&sysc_soc->list_lock);
3058
3059 return error;
3060}
3061
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003062/*
3063 * Ignore timers tagged with no-reset and no-idle. These are likely in use,
3064 * for example by drivers/clocksource/timer-ti-dm-systimer.c. If more checks
3065 * are needed, we could also look at the timer register configuration.
3066 */
3067static int sysc_check_active_timer(struct sysc *ddata)
3068{
3069 if (ddata->cap->type != TI_SYSC_OMAP2_TIMER &&
3070 ddata->cap->type != TI_SYSC_OMAP4_TIMER)
3071 return 0;
3072
3073 if ((ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) &&
3074 (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE))
Grygorii Strashko65fb7362020-11-18 16:19:00 +02003075 return -ENXIO;
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003076
3077 return 0;
3078}
3079
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07003080static const struct of_device_id sysc_match_table[] = {
3081 { .compatible = "simple-bus", },
3082 { /* sentinel */ },
3083};
3084
Tony Lindgren0eecc632017-10-10 14:23:43 -07003085static int sysc_probe(struct platform_device *pdev)
3086{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003087 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003088 struct sysc *ddata;
3089 int error;
3090
3091 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
3092 if (!ddata)
3093 return -ENOMEM;
3094
Tony Lindgren29281352020-11-16 12:57:13 +02003095 ddata->offsets[SYSC_REVISION] = -ENODEV;
3096 ddata->offsets[SYSC_SYSCONFIG] = -ENODEV;
3097 ddata->offsets[SYSC_SYSSTATUS] = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003098 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003099 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003100
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003101 error = sysc_init_soc(ddata);
3102 if (error)
3103 return error;
3104
Tony Lindgren70a65242017-12-15 09:41:09 -08003105 error = sysc_init_match(ddata);
3106 if (error)
3107 return error;
3108
Tony Lindgren566a9b052017-12-15 09:41:19 -08003109 error = sysc_init_dts_quirks(ddata);
3110 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003111 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003112
Tony Lindgren0eecc632017-10-10 14:23:43 -07003113 error = sysc_map_and_check_registers(ddata);
3114 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003115 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003116
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003117 error = sysc_init_sysc_mask(ddata);
3118 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003119 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003120
3121 error = sysc_init_idlemodes(ddata);
3122 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003123 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003124
3125 error = sysc_init_syss_mask(ddata);
3126 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003127 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003128
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003129 error = sysc_init_pdata(ddata);
3130 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003131 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003132
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003133 sysc_init_early_quirks(ddata);
3134
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003135 error = sysc_check_disabled_devices(ddata);
3136 if (error)
3137 return error;
3138
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003139 error = sysc_check_active_timer(ddata);
Tony Lindgren06a089e2021-08-11 08:34:46 +03003140 if (error == -ENXIO)
Tony Lindgren3ff340e2021-06-11 08:42:50 +03003141 ddata->reserved = true;
Tony Lindgren06a089e2021-08-11 08:34:46 +03003142 else if (error)
3143 return error;
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003144
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003145 error = sysc_get_clocks(ddata);
3146 if (error)
3147 return error;
3148
Tony Lindgren50622362018-04-16 10:20:27 -07003149 error = sysc_init_resets(ddata);
3150 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003151 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003152
3153 error = sysc_init_module(ddata);
3154 if (error)
3155 goto unprepare;
3156
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07003157 pm_runtime_enable(ddata->dev);
Zhang Qilongcea08162021-05-31 22:25:42 +08003158 error = pm_runtime_resume_and_get(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003159 if (error < 0) {
Tony Lindgren0eecc632017-10-10 14:23:43 -07003160 pm_runtime_disable(ddata->dev);
3161 goto unprepare;
3162 }
3163
Tero Kristocdc56c12019-10-07 15:29:31 +03003164 /* Balance use counts as PM runtime should have enabled these all */
Tero Kristocdc56c12019-10-07 15:29:31 +03003165 if (!(ddata->cfg.quirks &
3166 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))) {
3167 sysc_disable_main_clocks(ddata);
3168 sysc_disable_opt_clocks(ddata);
3169 sysc_clkdm_allow_idle(ddata);
3170 }
3171
Tony Lindgren4097c9a2020-11-16 12:57:13 +02003172 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
3173 reset_control_assert(ddata->rsts);
3174
Tony Lindgren0eecc632017-10-10 14:23:43 -07003175 sysc_show_registers(ddata);
3176
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003177 ddata->dev->type = &sysc_device_type;
Tony Lindgren3ff340e2021-06-11 08:42:50 +03003178
3179 if (!ddata->reserved) {
3180 error = of_platform_populate(ddata->dev->of_node,
3181 sysc_match_table,
3182 pdata ? pdata->auxdata : NULL,
3183 ddata->dev);
3184 if (error)
3185 goto err;
3186 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07003187
Tony Lindgren76f0f772018-02-23 08:28:45 -08003188 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
3189
3190 /* At least earlycon won't survive without deferred idle */
Tony Lindgrend0989132019-09-05 07:37:22 -07003191 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
3192 SYSC_QUIRK_NO_IDLE_ON_INIT |
Tony Lindgren76f0f772018-02-23 08:28:45 -08003193 SYSC_QUIRK_NO_RESET_ON_INIT)) {
3194 schedule_delayed_work(&ddata->idle_work, 3000);
3195 } else {
3196 pm_runtime_put(&pdev->dev);
3197 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07003198
3199 return 0;
3200
3201err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07003202 pm_runtime_put_sync(&pdev->dev);
3203 pm_runtime_disable(&pdev->dev);
3204unprepare:
3205 sysc_unprepare(ddata);
3206
3207 return error;
3208}
3209
Tony Lindgren684be5a2017-10-13 10:48:40 -07003210static int sysc_remove(struct platform_device *pdev)
3211{
3212 struct sysc *ddata = platform_get_drvdata(pdev);
3213 int error;
3214
Tony Lindgren76f0f772018-02-23 08:28:45 -08003215 cancel_delayed_work_sync(&ddata->idle_work);
3216
Zhang Qilongcea08162021-05-31 22:25:42 +08003217 error = pm_runtime_resume_and_get(ddata->dev);
Tony Lindgren684be5a2017-10-13 10:48:40 -07003218 if (error < 0) {
Tony Lindgren684be5a2017-10-13 10:48:40 -07003219 pm_runtime_disable(ddata->dev);
3220 goto unprepare;
3221 }
3222
3223 of_platform_depopulate(&pdev->dev);
3224
Tony Lindgren684be5a2017-10-13 10:48:40 -07003225 pm_runtime_put_sync(&pdev->dev);
3226 pm_runtime_disable(&pdev->dev);
Tony Lindgrena7b5d7c2021-02-18 13:06:57 +02003227
3228 if (!reset_control_status(ddata->rsts))
3229 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07003230
3231unprepare:
3232 sysc_unprepare(ddata);
3233
3234 return 0;
3235}
3236
Tony Lindgren0eecc632017-10-10 14:23:43 -07003237static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08003238 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
3239 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
3240 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
3241 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
3242 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
3243 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
3244 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
3245 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
3246 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
3247 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
3248 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08003249 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08003250 { .compatible = "ti,sysc-usb-host-fs",
3251 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05303252 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Suman Annab2745d92020-02-27 16:28:34 -06003253 { .compatible = "ti,sysc-pruss", .data = &sysc_pruss, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07003254 { },
3255};
3256MODULE_DEVICE_TABLE(of, sysc_match);
3257
3258static struct platform_driver sysc_driver = {
3259 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07003260 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07003261 .driver = {
3262 .name = "ti-sysc",
3263 .of_match_table = sysc_match,
3264 .pm = &sysc_pm_ops,
3265 },
3266};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003267
3268static int __init sysc_init(void)
3269{
3270 bus_register_notifier(&platform_bus_type, &sysc_nb);
3271
3272 return platform_driver_register(&sysc_driver);
3273}
3274module_init(sysc_init);
3275
3276static void __exit sysc_exit(void)
3277{
3278 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
3279 platform_driver_unregister(&sysc_driver);
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003280 sysc_cleanup_soc();
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003281}
3282module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003283
3284MODULE_DESCRIPTION("TI sysc interconnect target driver");
3285MODULE_LICENSE("GPL v2");