blob: a73c707d14c303fdb34a15c6e58bfcbcbde69e0a [file] [log] [blame]
Suman Anna54d66222019-08-13 04:13:32 -07001// SPDX-License-Identifier: GPL-2.0
Tony Lindgren0eecc632017-10-10 14:23:43 -07002/*
3 * ti-sysc.c - Texas Instruments sysc interconnect target driver
Tony Lindgren0eecc632017-10-10 14:23:43 -07004 */
5
6#include <linux/io.h>
7#include <linux/clk.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -08008#include <linux/clkdev.h>
Tony Lindgren9d8813612021-09-21 12:42:25 +03009#include <linux/cpu_pm.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080010#include <linux/delay.h>
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080011#include <linux/list.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070012#include <linux/module.h>
13#include <linux/platform_device.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080014#include <linux/pm_domain.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070015#include <linux/pm_runtime.h>
Tony Lindgren50622362018-04-16 10:20:27 -070016#include <linux/reset.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070017#include <linux/of_address.h>
18#include <linux/of_platform.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080019#include <linux/slab.h>
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080020#include <linux/sys_soc.h>
Tony Lindgrenb3e94312021-09-21 12:42:25 +030021#include <linux/timekeeping.h>
Faiz Abbas596e7952018-07-09 22:18:39 +053022#include <linux/iopoll.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080023
Tony Lindgren70a65242017-12-15 09:41:09 -080024#include <linux/platform_data/ti-sysc.h>
25
26#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070027
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080028#define DIS_ISP BIT(2)
29#define DIS_IVA BIT(1)
30#define DIS_SGX BIT(0)
31
32#define SOC_FLAG(match, flag) { .machine = match, .data = (void *)(flag), }
33
Tony Lindgrene4a8fc02020-06-10 15:31:54 -070034#define MAX_MODULE_SOFTRESET_WAIT 10000
Faiz Abbas596e7952018-07-09 22:18:39 +053035
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080036enum sysc_soc {
37 SOC_UNKNOWN,
38 SOC_2420,
39 SOC_2430,
40 SOC_3430,
41 SOC_3630,
42 SOC_4430,
43 SOC_4460,
44 SOC_4470,
45 SOC_5430,
46 SOC_AM3,
47 SOC_AM4,
48 SOC_DRA7,
49};
50
51struct sysc_address {
52 unsigned long base;
53 struct list_head node;
54};
55
Tony Lindgren9d8813612021-09-21 12:42:25 +030056struct sysc_module {
57 struct sysc *ddata;
58 struct list_head node;
59};
60
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080061struct sysc_soc_info {
62 unsigned long general_purpose:1;
63 enum sysc_soc soc;
Tony Lindgren9d8813612021-09-21 12:42:25 +030064 struct mutex list_lock; /* disabled and restored modules list lock */
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080065 struct list_head disabled_modules;
Tony Lindgren9d8813612021-09-21 12:42:25 +030066 struct list_head restored_modules;
67 struct notifier_block nb;
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080068};
Tony Lindgren0eecc632017-10-10 14:23:43 -070069
70enum sysc_clocks {
71 SYSC_FCK,
72 SYSC_ICK,
Tony Lindgren09dfe582018-04-16 10:25:52 -070073 SYSC_OPTFCK0,
74 SYSC_OPTFCK1,
75 SYSC_OPTFCK2,
76 SYSC_OPTFCK3,
77 SYSC_OPTFCK4,
78 SYSC_OPTFCK5,
79 SYSC_OPTFCK6,
80 SYSC_OPTFCK7,
Tony Lindgren0eecc632017-10-10 14:23:43 -070081 SYSC_MAX_CLOCKS,
82};
83
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080084static struct sysc_soc_info *sysc_soc;
85static const char * const reg_names[] = { "rev", "sysc", "syss", };
Tony Lindgrena54275f2019-03-21 11:00:21 -070086static const char * const clock_names[SYSC_MAX_CLOCKS] = {
87 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
88 "opt5", "opt6", "opt7",
89};
Tony Lindgren0eecc632017-10-10 14:23:43 -070090
Tony Lindgrenc5a2de92017-12-15 09:41:23 -080091#define SYSC_IDLEMODE_MASK 3
92#define SYSC_CLOCKACTIVITY_MASK 3
93
Tony Lindgren0eecc632017-10-10 14:23:43 -070094/**
95 * struct sysc - TI sysc interconnect target module registers and capabilities
96 * @dev: struct device pointer
97 * @module_pa: physical address of the interconnect target module
98 * @module_size: size of the interconnect target module
99 * @module_va: virtual address of the interconnect target module
100 * @offsets: register offsets from module base
Suman Annab58056d2019-08-13 04:13:32 -0700101 * @mdata: ti-sysc to hwmod translation data for a module
Tony Lindgren0eecc632017-10-10 14:23:43 -0700102 * @clocks: clocks used by the interconnect target module
Tony Lindgren09dfe582018-04-16 10:25:52 -0700103 * @clock_roles: clock role names for the found clocks
104 * @nr_clocks: number of clocks used by the interconnect target module
Suman Annab58056d2019-08-13 04:13:32 -0700105 * @rsts: resets used by the interconnect target module
Tony Lindgren0eecc632017-10-10 14:23:43 -0700106 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -0800107 * @cap: interconnect target module capabilities
108 * @cfg: interconnect target module configuration
Suman Annab58056d2019-08-13 04:13:32 -0700109 * @cookie: data used by legacy platform callbacks
Tony Lindgren566a9b052017-12-15 09:41:19 -0800110 * @name: name if available
111 * @revision: interconnect target module revision
Tony Lindgren3ff340e2021-06-11 08:42:50 +0300112 * @reserved: target module is reserved and already in use
Suman Annab58056d2019-08-13 04:13:32 -0700113 * @enabled: sysc runtime enabled status
Tony Lindgren62020f22018-02-22 13:59:44 -0800114 * @needs_resume: runtime resume needed on resume from suspend
Suman Annab58056d2019-08-13 04:13:32 -0700115 * @child_needs_resume: runtime resume needed for child on resume from suspend
116 * @disable_on_idle: status flag used for disabling modules with resets
117 * @idle_work: work structure used to perform delayed idle on a module
Tony Lindgrene64c0212020-02-24 12:58:03 -0800118 * @pre_reset_quirk: module specific pre-reset quirk
119 * @post_reset_quirk: module specific post-reset quirk
Tony Lindgren4e23be42019-06-10 04:48:05 -0700120 * @reset_done_quirk: module specific reset done quirk
Tony Lindgrend7f563d2019-08-14 05:18:16 -0700121 * @module_enable_quirk: module specific enable quirk
Tony Lindgrenc7d86692019-10-17 11:21:44 -0700122 * @module_disable_quirk: module specific disable quirk
Tony Lindgrene8639e12020-02-24 12:58:03 -0800123 * @module_unlock_quirk: module specific sysconfig unlock quirk
124 * @module_lock_quirk: module specific sysconfig lock quirk
Tony Lindgren0eecc632017-10-10 14:23:43 -0700125 */
126struct sysc {
127 struct device *dev;
128 u64 module_pa;
129 u32 module_size;
130 void __iomem *module_va;
131 int offsets[SYSC_MAX_REGS];
Tony Lindgrena3e92e72019-03-21 11:00:21 -0700132 struct ti_sysc_module_data *mdata;
Tony Lindgren09dfe582018-04-16 10:25:52 -0700133 struct clk **clocks;
134 const char **clock_roles;
135 int nr_clocks;
Tony Lindgren50622362018-04-16 10:20:27 -0700136 struct reset_control *rsts;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700137 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -0800138 const struct sysc_capabilities *cap;
139 struct sysc_config cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800140 struct ti_sysc_cookie cookie;
Tony Lindgren566a9b052017-12-15 09:41:19 -0800141 const char *name;
142 u32 revision;
Tony Lindgren95ec14fa2021-09-21 12:42:25 +0300143 u32 sysconfig;
Tony Lindgren3ff340e2021-06-11 08:42:50 +0300144 unsigned int reserved:1;
Tony Lindgren8383e252019-05-27 04:51:56 -0700145 unsigned int enabled:1;
146 unsigned int needs_resume:1;
147 unsigned int child_needs_resume:1;
Tony Lindgren76f0f772018-02-23 08:28:45 -0800148 struct delayed_work idle_work;
Tony Lindgrene64c0212020-02-24 12:58:03 -0800149 void (*pre_reset_quirk)(struct sysc *sysc);
150 void (*post_reset_quirk)(struct sysc *sysc);
Tony Lindgren4e23be42019-06-10 04:48:05 -0700151 void (*reset_done_quirk)(struct sysc *sysc);
Tony Lindgrend7f563d2019-08-14 05:18:16 -0700152 void (*module_enable_quirk)(struct sysc *sysc);
Tony Lindgrenc7d86692019-10-17 11:21:44 -0700153 void (*module_disable_quirk)(struct sysc *sysc);
Tony Lindgrene8639e12020-02-24 12:58:03 -0800154 void (*module_unlock_quirk)(struct sysc *sysc);
155 void (*module_lock_quirk)(struct sysc *sysc);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700156};
157
Tony Lindgren4014c082018-12-10 14:11:26 -0800158static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
159 bool is_child);
160
Tony Lindgrenb7182b42019-03-21 11:00:21 -0700161static void sysc_write(struct sysc *ddata, int offset, u32 value)
Faiz Abbas596e7952018-07-09 22:18:39 +0530162{
Tony Lindgren5aa91292019-05-27 04:51:53 -0700163 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
164 writew_relaxed(value & 0xffff, ddata->module_va + offset);
165
166 /* Only i2c revision has LO and HI register with stride of 4 */
167 if (ddata->offsets[SYSC_REVISION] >= 0 &&
168 offset == ddata->offsets[SYSC_REVISION]) {
169 u16 hi = value >> 16;
170
171 writew_relaxed(hi, ddata->module_va + offset + 4);
172 }
173
174 return;
175 }
176
Faiz Abbas596e7952018-07-09 22:18:39 +0530177 writel_relaxed(value, ddata->module_va + offset);
178}
179
Tony Lindgren566a9b052017-12-15 09:41:19 -0800180static u32 sysc_read(struct sysc *ddata, int offset)
181{
182 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
183 u32 val;
184
185 val = readw_relaxed(ddata->module_va + offset);
Tony Lindgren5aa91292019-05-27 04:51:53 -0700186
187 /* Only i2c revision has LO and HI register with stride of 4 */
188 if (ddata->offsets[SYSC_REVISION] >= 0 &&
189 offset == ddata->offsets[SYSC_REVISION]) {
190 u16 tmp = readw_relaxed(ddata->module_va + offset + 4);
191
192 val |= tmp << 16;
193 }
Tony Lindgren566a9b052017-12-15 09:41:19 -0800194
195 return val;
196 }
197
198 return readl_relaxed(ddata->module_va + offset);
199}
200
Tony Lindgren09dfe582018-04-16 10:25:52 -0700201static bool sysc_opt_clks_needed(struct sysc *ddata)
202{
203 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
204}
205
Tony Lindgren0eecc632017-10-10 14:23:43 -0700206static u32 sysc_read_revision(struct sysc *ddata)
207{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800208 int offset = ddata->offsets[SYSC_REVISION];
209
210 if (offset < 0)
211 return 0;
212
213 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700214}
215
Tony Lindgrene0db94f2019-05-27 04:51:53 -0700216static u32 sysc_read_sysconfig(struct sysc *ddata)
217{
218 int offset = ddata->offsets[SYSC_SYSCONFIG];
219
220 if (offset < 0)
221 return 0;
222
223 return sysc_read(ddata, offset);
224}
225
226static u32 sysc_read_sysstatus(struct sysc *ddata)
227{
228 int offset = ddata->offsets[SYSC_SYSSTATUS];
229
230 if (offset < 0)
231 return 0;
232
233 return sysc_read(ddata, offset);
234}
235
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300236static int sysc_poll_reset_sysstatus(struct sysc *ddata)
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700237{
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300238 int error, retries;
239 u32 syss_done, rstval;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700240
241 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
242 syss_done = 0;
243 else
244 syss_done = ddata->cfg.syss_mask;
245
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300246 if (likely(!timekeeping_suspended)) {
Tony Lindgren9f911392020-07-02 10:44:20 -0700247 error = readx_poll_timeout_atomic(sysc_read_sysstatus, ddata,
248 rstval, (rstval & ddata->cfg.syss_mask) ==
249 syss_done, 100, MAX_MODULE_SOFTRESET_WAIT);
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300250 } else {
251 retries = MAX_MODULE_SOFTRESET_WAIT;
252 while (retries--) {
253 rstval = sysc_read_sysstatus(ddata);
254 if ((rstval & ddata->cfg.syss_mask) == syss_done)
255 return 0;
256 udelay(2); /* Account for udelay flakeyness */
257 }
258 error = -ETIMEDOUT;
259 }
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700260
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300261 return error;
262}
263
264static int sysc_poll_reset_sysconfig(struct sysc *ddata)
265{
266 int error, retries;
267 u32 sysc_mask, rstval;
268
269 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
270
271 if (likely(!timekeeping_suspended)) {
Tony Lindgren9f911392020-07-02 10:44:20 -0700272 error = readx_poll_timeout_atomic(sysc_read_sysconfig, ddata,
273 rstval, !(rstval & sysc_mask),
274 100, MAX_MODULE_SOFTRESET_WAIT);
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300275 } else {
276 retries = MAX_MODULE_SOFTRESET_WAIT;
277 while (retries--) {
278 rstval = sysc_read_sysconfig(ddata);
279 if (!(rstval & sysc_mask))
280 return 0;
281 udelay(2); /* Account for udelay flakeyness */
282 }
283 error = -ETIMEDOUT;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700284 }
285
286 return error;
287}
288
Tony Lindgrenb3e94312021-09-21 12:42:25 +0300289/* Poll on reset status */
290static int sysc_wait_softreset(struct sysc *ddata)
291{
292 int syss_offset, error = 0;
293
294 if (ddata->cap->regbits->srst_shift < 0)
295 return 0;
296
297 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
298
299 if (syss_offset >= 0)
300 error = sysc_poll_reset_sysstatus(ddata);
301 else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS)
302 error = sysc_poll_reset_sysconfig(ddata);
303
304 return error;
305}
306
Tony Lindgrena54275f2019-03-21 11:00:21 -0700307static int sysc_add_named_clock_from_child(struct sysc *ddata,
308 const char *name,
309 const char *optfck_name)
310{
311 struct device_node *np = ddata->dev->of_node;
312 struct device_node *child;
313 struct clk_lookup *cl;
314 struct clk *clock;
315 const char *n;
316
317 if (name)
318 n = name;
319 else
320 n = optfck_name;
321
322 /* Does the clock alias already exist? */
323 clock = of_clk_get_by_name(np, n);
324 if (!IS_ERR(clock)) {
325 clk_put(clock);
326
327 return 0;
328 }
329
330 child = of_get_next_available_child(np, NULL);
331 if (!child)
332 return -ENODEV;
333
334 clock = devm_get_clk_from_child(ddata->dev, child, name);
335 if (IS_ERR(clock))
336 return PTR_ERR(clock);
337
338 /*
339 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
340 * limit for clk_get(). If cl ever needs to be freed, it should be done
341 * with clkdev_drop().
342 */
Zheng Yongjund995d3d2020-12-29 21:51:47 +0800343 cl = kzalloc(sizeof(*cl), GFP_KERNEL);
Tony Lindgrena54275f2019-03-21 11:00:21 -0700344 if (!cl)
345 return -ENOMEM;
346
347 cl->con_id = n;
348 cl->dev_id = dev_name(ddata->dev);
349 cl->clk = clock;
350 clkdev_add(cl);
351
352 clk_put(clock);
353
354 return 0;
355}
356
357static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
358{
359 const char *optfck_name;
360 int error, index;
361
362 if (ddata->nr_clocks < SYSC_OPTFCK0)
363 index = SYSC_OPTFCK0;
364 else
365 index = ddata->nr_clocks;
366
367 if (name)
368 optfck_name = name;
369 else
370 optfck_name = clock_names[index];
371
372 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
373 if (error)
374 return error;
375
376 ddata->clock_roles[index] = optfck_name;
377 ddata->nr_clocks++;
378
379 return 0;
380}
381
Tony Lindgren09dfe582018-04-16 10:25:52 -0700382static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700383{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700384 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700385
Tony Lindgren09dfe582018-04-16 10:25:52 -0700386 if (!strncmp(clock_names[SYSC_FCK], name, 3))
387 index = SYSC_FCK;
388 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
389 index = SYSC_ICK;
390
391 if (index < 0) {
392 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700393 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700394 index = i;
395 break;
396 }
397 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700398 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700399
400 if (index < 0) {
401 dev_err(ddata->dev, "clock %s not added\n", name);
402 return index;
403 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700404
405 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
406 if (IS_ERR(ddata->clocks[index])) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700407 dev_err(ddata->dev, "clock get error for %s: %li\n",
408 name, PTR_ERR(ddata->clocks[index]));
409
410 return PTR_ERR(ddata->clocks[index]);
411 }
412
413 error = clk_prepare(ddata->clocks[index]);
414 if (error) {
415 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
416 name, error);
417
418 return error;
419 }
420
421 return 0;
422}
423
424static int sysc_get_clocks(struct sysc *ddata)
425{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700426 struct device_node *np = ddata->dev->of_node;
427 struct property *prop;
428 const char *name;
429 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700430
Kees Cook20749052018-06-18 10:45:49 -0700431 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700432 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700433 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700434 GFP_KERNEL);
435 if (!ddata->clock_roles)
436 return -ENOMEM;
437
438 of_property_for_each_string(np, "clock-names", prop, name) {
439 if (!strncmp(clock_names[SYSC_FCK], name, 3))
440 nr_fck++;
441 if (!strncmp(clock_names[SYSC_ICK], name, 3))
442 nr_ick++;
443 ddata->clock_roles[ddata->nr_clocks] = name;
444 ddata->nr_clocks++;
445 }
446
447 if (ddata->nr_clocks < 1)
448 return 0;
449
Tony Lindgrena54275f2019-03-21 11:00:21 -0700450 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
451 error = sysc_init_ext_opt_clock(ddata, NULL);
452 if (error)
453 return error;
454 }
455
Tony Lindgren09dfe582018-04-16 10:25:52 -0700456 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
457 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
458
459 return -EINVAL;
460 }
461
462 if (nr_fck > 1 || nr_ick > 1) {
463 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
464
465 return -EINVAL;
466 }
467
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800468 /* Always add a slot for main clocks fck and ick even if unused */
469 if (!nr_fck)
470 ddata->nr_clocks++;
471 if (!nr_ick)
472 ddata->nr_clocks++;
473
Kees Cook20749052018-06-18 10:45:49 -0700474 ddata->clocks = devm_kcalloc(ddata->dev,
475 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700476 GFP_KERNEL);
477 if (!ddata->clocks)
478 return -ENOMEM;
479
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800480 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
481 const char *name = ddata->clock_roles[i];
482
483 if (!name)
484 continue;
485
486 error = sysc_get_one_clock(ddata, name);
Tony Lindgren2783d062019-09-05 13:01:29 -0700487 if (error)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700488 return error;
489 }
490
491 return 0;
492}
493
Tony Lindgrend8789702019-03-21 11:00:21 -0700494static int sysc_enable_main_clocks(struct sysc *ddata)
495{
496 struct clk *clock;
497 int i, error;
498
499 if (!ddata->clocks)
500 return 0;
501
502 for (i = 0; i < SYSC_OPTFCK0; i++) {
503 clock = ddata->clocks[i];
504
505 /* Main clocks may not have ick */
506 if (IS_ERR_OR_NULL(clock))
507 continue;
508
509 error = clk_enable(clock);
510 if (error)
511 goto err_disable;
512 }
513
514 return 0;
515
516err_disable:
517 for (i--; i >= 0; i--) {
518 clock = ddata->clocks[i];
519
520 /* Main clocks may not have ick */
521 if (IS_ERR_OR_NULL(clock))
522 continue;
523
524 clk_disable(clock);
525 }
526
527 return error;
528}
529
530static void sysc_disable_main_clocks(struct sysc *ddata)
531{
532 struct clk *clock;
533 int i;
534
535 if (!ddata->clocks)
536 return;
537
538 for (i = 0; i < SYSC_OPTFCK0; i++) {
539 clock = ddata->clocks[i];
540 if (IS_ERR_OR_NULL(clock))
541 continue;
542
543 clk_disable(clock);
544 }
545}
546
547static int sysc_enable_opt_clocks(struct sysc *ddata)
548{
549 struct clk *clock;
550 int i, error;
551
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800552 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700553 return 0;
554
555 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
556 clock = ddata->clocks[i];
557
558 /* Assume no holes for opt clocks */
559 if (IS_ERR_OR_NULL(clock))
560 return 0;
561
562 error = clk_enable(clock);
563 if (error)
564 goto err_disable;
565 }
566
567 return 0;
568
569err_disable:
570 for (i--; i >= 0; i--) {
571 clock = ddata->clocks[i];
572 if (IS_ERR_OR_NULL(clock))
573 continue;
574
575 clk_disable(clock);
576 }
577
578 return error;
579}
580
581static void sysc_disable_opt_clocks(struct sysc *ddata)
582{
583 struct clk *clock;
584 int i;
585
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800586 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700587 return;
588
589 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
590 clock = ddata->clocks[i];
591
592 /* Assume no holes for opt clocks */
593 if (IS_ERR_OR_NULL(clock))
594 return;
595
596 clk_disable(clock);
597 }
598}
599
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700600static void sysc_clkdm_deny_idle(struct sysc *ddata)
601{
602 struct ti_sysc_platform_data *pdata;
603
Tony Lindgren94f63452019-12-12 08:57:58 -0800604 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700605 return;
606
607 pdata = dev_get_platdata(ddata->dev);
608 if (pdata && pdata->clkdm_deny_idle)
609 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
610}
611
612static void sysc_clkdm_allow_idle(struct sysc *ddata)
613{
614 struct ti_sysc_platform_data *pdata;
615
Tony Lindgren94f63452019-12-12 08:57:58 -0800616 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700617 return;
618
619 pdata = dev_get_platdata(ddata->dev);
620 if (pdata && pdata->clkdm_allow_idle)
621 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
622}
623
Tony Lindgren0eecc632017-10-10 14:23:43 -0700624/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700625 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700626 * @ddata: device driver data
627 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700628 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700629 */
630static int sysc_init_resets(struct sysc *ddata)
631{
Tony Lindgren50622362018-04-16 10:20:27 -0700632 ddata->rsts =
Tero Kristobb88b862019-08-07 15:46:05 +0300633 devm_reset_control_get_optional_shared(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700634
zhengbin3f2c4202019-11-18 18:37:32 +0800635 return PTR_ERR_OR_ZERO(ddata->rsts);
Tony Lindgren50622362018-04-16 10:20:27 -0700636}
637
638/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700639 * sysc_parse_and_check_child_range - parses module IO region from ranges
640 * @ddata: device driver data
641 *
642 * In general we only need rev, syss, and sysc registers and not the whole
643 * module range. But we do want the offsets for these registers from the
644 * module base. This allows us to check them against the legacy hwmod
645 * platform data. Let's also check the ranges are configured properly.
646 */
647static int sysc_parse_and_check_child_range(struct sysc *ddata)
648{
649 struct device_node *np = ddata->dev->of_node;
650 const __be32 *ranges;
651 u32 nr_addr, nr_size;
652 int len, error;
653
654 ranges = of_get_property(np, "ranges", &len);
655 if (!ranges) {
656 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
657
658 return -ENOENT;
659 }
660
661 len /= sizeof(*ranges);
662
663 if (len < 3) {
664 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
665
666 return -EINVAL;
667 }
668
669 error = of_property_read_u32(np, "#address-cells", &nr_addr);
670 if (error)
671 return -ENOENT;
672
673 error = of_property_read_u32(np, "#size-cells", &nr_size);
674 if (error)
675 return -ENOENT;
676
677 if (nr_addr != 1 || nr_size != 1) {
678 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
679
680 return -EINVAL;
681 }
682
683 ranges++;
684 ddata->module_pa = of_translate_address(np, ranges++);
685 ddata->module_size = be32_to_cpup(ranges);
686
Tony Lindgren0eecc632017-10-10 14:23:43 -0700687 return 0;
688}
689
Tony Lindgren4700a002021-03-08 11:35:07 +0200690/* Interconnect instances to probe before l4_per instances */
691static struct resource early_bus_ranges[] = {
692 /* am3/4 l4_wkup */
693 { .start = 0x44c00000, .end = 0x44c00000 + 0x300000, },
694 /* omap4/5 and dra7 l4_cfg */
695 { .start = 0x4a000000, .end = 0x4a000000 + 0x300000, },
696 /* omap4 l4_wkup */
697 { .start = 0x4a300000, .end = 0x4a300000 + 0x30000, },
698 /* omap5 and dra7 l4_wkup without dra7 dcan segment */
699 { .start = 0x4ae00000, .end = 0x4ae00000 + 0x30000, },
700};
701
702static atomic_t sysc_defer = ATOMIC_INIT(10);
703
704/**
705 * sysc_defer_non_critical - defer non_critical interconnect probing
706 * @ddata: device driver data
707 *
708 * We want to probe l4_cfg and l4_wkup interconnect instances before any
709 * l4_per instances as l4_per instances depend on resources on l4_cfg and
710 * l4_wkup interconnects.
711 */
712static int sysc_defer_non_critical(struct sysc *ddata)
713{
714 struct resource *res;
715 int i;
716
717 if (!atomic_read(&sysc_defer))
718 return 0;
719
720 for (i = 0; i < ARRAY_SIZE(early_bus_ranges); i++) {
721 res = &early_bus_ranges[i];
722 if (ddata->module_pa >= res->start &&
723 ddata->module_pa <= res->end) {
724 atomic_set(&sysc_defer, 0);
725
726 return 0;
727 }
728 }
729
730 atomic_dec_if_positive(&sysc_defer);
731
732 return -EPROBE_DEFER;
733}
734
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800735static struct device_node *stdout_path;
736
737static void sysc_init_stdout_path(struct sysc *ddata)
738{
739 struct device_node *np = NULL;
740 const char *uart;
741
742 if (IS_ERR(stdout_path))
743 return;
744
745 if (stdout_path)
746 return;
747
748 np = of_find_node_by_path("/chosen");
749 if (!np)
750 goto err;
751
752 uart = of_get_property(np, "stdout-path", NULL);
753 if (!uart)
754 goto err;
755
756 np = of_find_node_by_path(uart);
757 if (!np)
758 goto err;
759
760 stdout_path = np;
761
762 return;
763
764err:
765 stdout_path = ERR_PTR(-ENODEV);
766}
767
768static void sysc_check_quirk_stdout(struct sysc *ddata,
769 struct device_node *np)
770{
771 sysc_init_stdout_path(ddata);
772 if (np != stdout_path)
773 return;
774
775 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
776 SYSC_QUIRK_NO_RESET_ON_INIT;
777}
778
Tony Lindgren0eecc632017-10-10 14:23:43 -0700779/**
780 * sysc_check_one_child - check child configuration
781 * @ddata: device driver data
782 * @np: child device node
783 *
784 * Let's avoid messy situations where we have new interconnect target
785 * node but children have "ti,hwmods". These belong to the interconnect
786 * target node and are managed by this driver.
787 */
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530788static void sysc_check_one_child(struct sysc *ddata,
789 struct device_node *np)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700790{
791 const char *name;
792
793 name = of_get_property(np, "ti,hwmods", NULL);
Tony Lindgren7320fd32020-02-24 12:58:03 -0800794 if (name && !of_device_is_compatible(np, "ti,sysc"))
Tony Lindgren0eecc632017-10-10 14:23:43 -0700795 dev_warn(ddata->dev, "really a child ti,hwmods property?");
796
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800797 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800798 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700799}
800
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530801static void sysc_check_children(struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700802{
803 struct device_node *child;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700804
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530805 for_each_child_of_node(ddata->dev->of_node, child)
806 sysc_check_one_child(ddata, child);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700807}
808
Tony Lindgrena7199e22017-12-15 09:41:14 -0800809/*
810 * So far only I2C uses 16-bit read access with clockactivity with revision
811 * in two registers with stride of 4. We can detect this based on the rev
812 * register size to configure things far enough to be able to properly read
813 * the revision register.
814 */
815static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
816{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800817 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800818 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800819}
820
Tony Lindgren0eecc632017-10-10 14:23:43 -0700821/**
822 * sysc_parse_one - parses the interconnect target module registers
823 * @ddata: device driver data
824 * @reg: register to parse
825 */
826static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
827{
828 struct resource *res;
829 const char *name;
830
831 switch (reg) {
832 case SYSC_REVISION:
833 case SYSC_SYSCONFIG:
834 case SYSC_SYSSTATUS:
835 name = reg_names[reg];
836 break;
837 default:
838 return -EINVAL;
839 }
840
841 res = platform_get_resource_byname(to_platform_device(ddata->dev),
842 IORESOURCE_MEM, name);
843 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700844 ddata->offsets[reg] = -ENODEV;
845
846 return 0;
847 }
848
849 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800850 if (reg == SYSC_REVISION)
851 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700852
853 return 0;
854}
855
856static int sysc_parse_registers(struct sysc *ddata)
857{
858 int i, error;
859
860 for (i = 0; i < SYSC_MAX_REGS; i++) {
861 error = sysc_parse_one(ddata, i);
862 if (error)
863 return error;
864 }
865
866 return 0;
867}
868
869/**
870 * sysc_check_registers - check for misconfigured register overlaps
871 * @ddata: device driver data
872 */
873static int sysc_check_registers(struct sysc *ddata)
874{
875 int i, j, nr_regs = 0, nr_matches = 0;
876
877 for (i = 0; i < SYSC_MAX_REGS; i++) {
878 if (ddata->offsets[i] < 0)
879 continue;
880
881 if (ddata->offsets[i] > (ddata->module_size - 4)) {
882 dev_err(ddata->dev, "register outside module range");
883
884 return -EINVAL;
885 }
886
887 for (j = 0; j < SYSC_MAX_REGS; j++) {
888 if (ddata->offsets[j] < 0)
889 continue;
890
891 if (ddata->offsets[i] == ddata->offsets[j])
892 nr_matches++;
893 }
894 nr_regs++;
895 }
896
Tony Lindgren0eecc632017-10-10 14:23:43 -0700897 if (nr_matches > nr_regs) {
898 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
899 nr_regs, nr_matches);
900
901 return -EINVAL;
902 }
903
904 return 0;
905}
906
907/**
Lee Jones4e001852021-05-26 09:10:37 +0100908 * sysc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700909 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700910 *
911 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700912 * within the interconnect target module range. For example, SGX has
913 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
914 * has them at offset 0x1200 in the CPSW_WR child. Usually the
915 * the interconnect target module registers are at the beginning of
916 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700917 */
918static int sysc_ioremap(struct sysc *ddata)
919{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700920 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700921
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700922 if (ddata->offsets[SYSC_REVISION] < 0 &&
923 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
924 ddata->offsets[SYSC_SYSSTATUS] < 0) {
925 size = ddata->module_size;
926 } else {
927 size = max3(ddata->offsets[SYSC_REVISION],
928 ddata->offsets[SYSC_SYSCONFIG],
929 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700930
Tony Lindgren4e23be42019-06-10 04:48:05 -0700931 if (size < SZ_1K)
932 size = SZ_1K;
933
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700934 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700935 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700936 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700937
Tony Lindgren0eecc632017-10-10 14:23:43 -0700938 ddata->module_va = devm_ioremap(ddata->dev,
939 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700940 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700941 if (!ddata->module_va)
942 return -EIO;
943
944 return 0;
945}
946
947/**
948 * sysc_map_and_check_registers - ioremap and check device registers
949 * @ddata: device driver data
950 */
951static int sysc_map_and_check_registers(struct sysc *ddata)
952{
Tony Lindgren29281352020-11-16 12:57:13 +0200953 struct device_node *np = ddata->dev->of_node;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700954 int error;
955
956 error = sysc_parse_and_check_child_range(ddata);
957 if (error)
958 return error;
959
Tony Lindgren4700a002021-03-08 11:35:07 +0200960 error = sysc_defer_non_critical(ddata);
961 if (error)
962 return error;
963
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530964 sysc_check_children(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700965
Tony Lindgren7bad5af2021-03-08 11:35:06 +0200966 if (!of_get_property(np, "reg", NULL))
967 return 0;
968
Tony Lindgren0eecc632017-10-10 14:23:43 -0700969 error = sysc_parse_registers(ddata);
970 if (error)
971 return error;
972
973 error = sysc_ioremap(ddata);
974 if (error)
975 return error;
976
977 error = sysc_check_registers(ddata);
978 if (error)
979 return error;
980
981 return 0;
982}
983
984/**
985 * sysc_show_rev - read and show interconnect target module revision
986 * @bufp: buffer to print the information to
987 * @ddata: device driver data
988 */
989static int sysc_show_rev(char *bufp, struct sysc *ddata)
990{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800991 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700992
993 if (ddata->offsets[SYSC_REVISION] < 0)
994 return sprintf(bufp, ":NA");
995
Tony Lindgren566a9b052017-12-15 09:41:19 -0800996 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700997
998 return len;
999}
1000
1001static int sysc_show_reg(struct sysc *ddata,
1002 char *bufp, enum sysc_registers reg)
1003{
1004 if (ddata->offsets[reg] < 0)
1005 return sprintf(bufp, ":NA");
1006
1007 return sprintf(bufp, ":%x", ddata->offsets[reg]);
1008}
1009
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001010static int sysc_show_name(char *bufp, struct sysc *ddata)
1011{
1012 if (!ddata->name)
1013 return 0;
1014
1015 return sprintf(bufp, ":%s", ddata->name);
1016}
1017
Tony Lindgren0eecc632017-10-10 14:23:43 -07001018/**
1019 * sysc_show_registers - show information about interconnect target module
1020 * @ddata: device driver data
1021 */
1022static void sysc_show_registers(struct sysc *ddata)
1023{
1024 char buf[128];
1025 char *bufp = buf;
1026 int i;
1027
1028 for (i = 0; i < SYSC_MAX_REGS; i++)
1029 bufp += sysc_show_reg(ddata, bufp, i);
1030
1031 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001032 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001033
1034 dev_dbg(ddata->dev, "%llx:%x%s\n",
1035 ddata->module_pa, ddata->module_size,
1036 buf);
1037}
1038
Tony Lindgrene8639e12020-02-24 12:58:03 -08001039/**
1040 * sysc_write_sysconfig - handle sysconfig quirks for register write
1041 * @ddata: device driver data
1042 * @value: register value
1043 */
1044static void sysc_write_sysconfig(struct sysc *ddata, u32 value)
1045{
1046 if (ddata->module_unlock_quirk)
1047 ddata->module_unlock_quirk(ddata);
1048
1049 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], value);
1050
1051 if (ddata->module_lock_quirk)
1052 ddata->module_lock_quirk(ddata);
1053}
1054
Roger Quadrosd59b6052019-04-08 12:52:39 +03001055#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001056#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +03001057
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001058/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001059static int sysc_enable_module(struct device *dev)
1060{
1061 struct sysc *ddata;
1062 const struct sysc_regbits *regbits;
1063 u32 reg, idlemodes, best_mode;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001064 int error;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001065
1066 ddata = dev_get_drvdata(dev);
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001067
1068 /*
1069 * Some modules like DSS reset automatically on idle. Enable optional
1070 * reset clocks and wait for OCP softreset to complete.
1071 */
1072 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET) {
1073 error = sysc_enable_opt_clocks(ddata);
1074 if (error) {
1075 dev_err(ddata->dev,
1076 "Optional clocks failed for enable: %i\n",
1077 error);
1078 return error;
1079 }
1080 }
Tony Lindgrene275d212020-10-26 10:08:47 +02001081 /*
1082 * Some modules like i2c and hdq1w have unusable reset status unless
1083 * the module reset quirk is enabled. Skip status check on enable.
1084 */
1085 if (!(ddata->cfg.quirks & SYSC_MODULE_QUIRK_ENA_RESETDONE)) {
1086 error = sysc_wait_softreset(ddata);
1087 if (error)
1088 dev_warn(ddata->dev, "OCP softreset timed out\n");
1089 }
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001090 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET)
1091 sysc_disable_opt_clocks(ddata);
1092
1093 /*
1094 * Some subsystem private interconnects, like DSS top level module,
1095 * need only the automatic OCP softreset handling with no sysconfig
1096 * register bits to configure.
1097 */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001098 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1099 return 0;
1100
Roger Quadrosd59b6052019-04-08 12:52:39 +03001101 regbits = ddata->cap->regbits;
1102 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1103
Tony Lindgren08b91dd2020-05-31 12:37:54 -07001104 /*
1105 * Set CLOCKACTIVITY, we only use it for ick. And we only configure it
1106 * based on the SYSC_QUIRK_USE_CLOCKACT flag, not based on the hardware
1107 * capabilities. See the old HWMOD_SET_DEFAULT_CLOCKACT flag.
1108 */
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001109 if (regbits->clkact_shift >= 0 &&
Tony Lindgren08b91dd2020-05-31 12:37:54 -07001110 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT))
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001111 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
1112
Roger Quadrosd59b6052019-04-08 12:52:39 +03001113 /* Set SIDLE mode */
1114 idlemodes = ddata->cfg.sidlemodes;
1115 if (!idlemodes || regbits->sidle_shift < 0)
1116 goto set_midle;
1117
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001118 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
1119 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
1120 best_mode = SYSC_IDLE_NO;
1121 } else {
1122 best_mode = fls(ddata->cfg.sidlemodes) - 1;
1123 if (best_mode > SYSC_IDLE_MASK) {
1124 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1125 return -EINVAL;
1126 }
Tony Lindgren6e09f492019-05-27 04:51:55 -07001127
1128 /* Set WAKEUP */
1129 if (regbits->enwkup_shift >= 0 &&
1130 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
1131 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001132 }
1133
1134 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1135 reg |= best_mode << regbits->sidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001136 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001137
1138set_midle:
1139 /* Set MIDLE mode */
1140 idlemodes = ddata->cfg.midlemodes;
1141 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -07001142 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001143
1144 best_mode = fls(ddata->cfg.midlemodes) - 1;
1145 if (best_mode > SYSC_IDLE_MASK) {
1146 dev_err(dev, "%s: invalid midlemode\n", __func__);
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001147 error = -EINVAL;
1148 goto save_context;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001149 }
1150
Tony Lindgren03856e92019-10-21 13:36:09 -07001151 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_MSTANDBY)
1152 best_mode = SYSC_IDLE_NO;
1153
Roger Quadrosd59b6052019-04-08 12:52:39 +03001154 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1155 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001156 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001157
Tony Lindgreneec26552019-05-27 04:51:54 -07001158set_autoidle:
1159 /* Autoidle bit must enabled separately if available */
1160 if (regbits->autoidle_shift >= 0 &&
1161 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
1162 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001163 sysc_write_sysconfig(ddata, reg);
Tony Lindgreneec26552019-05-27 04:51:54 -07001164 }
1165
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001166 error = 0;
1167
1168save_context:
1169 /* Save context and flush posted write */
1170 ddata->sysconfig = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
Tony Lindgren5ce8aee2020-05-27 06:49:29 -07001171
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001172 if (ddata->module_enable_quirk)
1173 ddata->module_enable_quirk(ddata);
1174
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001175 return error;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001176}
1177
1178static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
1179{
1180 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
1181 *best_mode = SYSC_IDLE_SMART_WKUP;
1182 else if (idlemodes & BIT(SYSC_IDLE_SMART))
1183 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -07001184 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +03001185 *best_mode = SYSC_IDLE_FORCE;
1186 else
1187 return -EINVAL;
1188
1189 return 0;
1190}
1191
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001192/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001193static int sysc_disable_module(struct device *dev)
1194{
1195 struct sysc *ddata;
1196 const struct sysc_regbits *regbits;
1197 u32 reg, idlemodes, best_mode;
1198 int ret;
1199
1200 ddata = dev_get_drvdata(dev);
1201 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1202 return 0;
1203
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001204 if (ddata->module_disable_quirk)
1205 ddata->module_disable_quirk(ddata);
1206
Roger Quadrosd59b6052019-04-08 12:52:39 +03001207 regbits = ddata->cap->regbits;
1208 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1209
1210 /* Set MIDLE mode */
1211 idlemodes = ddata->cfg.midlemodes;
1212 if (!idlemodes || regbits->midle_shift < 0)
1213 goto set_sidle;
1214
1215 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1216 if (ret) {
1217 dev_err(dev, "%s: invalid midlemode\n", __func__);
1218 return ret;
1219 }
1220
Tony Lindgren93c60482019-12-09 13:55:15 -08001221 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_MSTANDBY) ||
1222 ddata->cfg.quirks & (SYSC_QUIRK_FORCE_MSTANDBY))
Tony Lindgren03856e92019-10-21 13:36:09 -07001223 best_mode = SYSC_IDLE_FORCE;
1224
Roger Quadrosd59b6052019-04-08 12:52:39 +03001225 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1226 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001227 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001228
1229set_sidle:
1230 /* Set SIDLE mode */
1231 idlemodes = ddata->cfg.sidlemodes;
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001232 if (!idlemodes || regbits->sidle_shift < 0) {
1233 ret = 0;
1234 goto save_context;
1235 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001236
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001237 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
1238 best_mode = SYSC_IDLE_FORCE;
1239 } else {
1240 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1241 if (ret) {
1242 dev_err(dev, "%s: invalid sidlemode\n", __func__);
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001243 ret = -EINVAL;
1244 goto save_context;
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001245 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001246 }
1247
1248 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1249 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -07001250 if (regbits->autoidle_shift >= 0 &&
1251 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1252 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001253 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001254
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001255 ret = 0;
Tony Lindgren5ce8aee2020-05-27 06:49:29 -07001256
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001257save_context:
1258 /* Save context and flush posted write */
1259 ddata->sysconfig = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1260
1261 return ret;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001262}
1263
Tony Lindgrenff437282019-03-21 11:00:21 -07001264static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1265 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001266{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001267 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001268 int error;
1269
1270 pdata = dev_get_platdata(ddata->dev);
1271 if (!pdata)
1272 return 0;
1273
1274 if (!pdata->idle_module)
1275 return -ENODEV;
1276
1277 error = pdata->idle_module(dev, &ddata->cookie);
1278 if (error)
1279 dev_err(dev, "%s: could not idle: %i\n",
1280 __func__, error);
1281
Tero Kristo4345f0d2019-08-07 15:46:04 +03001282 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001283
Tony Lindgrenff437282019-03-21 11:00:21 -07001284 return 0;
1285}
1286
1287static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1288 struct sysc *ddata)
1289{
1290 struct ti_sysc_platform_data *pdata;
1291 int error;
1292
1293 pdata = dev_get_platdata(ddata->dev);
1294 if (!pdata)
1295 return 0;
1296
1297 if (!pdata->enable_module)
1298 return -ENODEV;
1299
1300 error = pdata->enable_module(dev, &ddata->cookie);
1301 if (error)
1302 dev_err(dev, "%s: could not enable: %i\n",
1303 __func__, error);
1304
Tero Kristobf59ebb2019-10-07 15:29:29 +03001305 reset_control_deassert(ddata->rsts);
1306
Tony Lindgrenff437282019-03-21 11:00:21 -07001307 return 0;
1308}
1309
1310static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1311{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001312 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001313 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001314
1315 ddata = dev_get_drvdata(dev);
1316
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001317 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001318 return 0;
1319
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001320 sysc_clkdm_deny_idle(ddata);
1321
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001322 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001323 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001324 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001325 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001326 } else {
1327 error = sysc_disable_module(dev);
1328 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001329 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001330 }
1331
Tony Lindgrend8789702019-03-21 11:00:21 -07001332 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001333
Tony Lindgrend8789702019-03-21 11:00:21 -07001334 if (sysc_opt_clks_needed(ddata))
1335 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001336
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001337 ddata->enabled = false;
1338
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001339err_allow_idle:
Tero Kristob6036312019-08-07 15:46:03 +03001340 sysc_clkdm_allow_idle(ddata);
1341
Tony Lindgren4097c9a2020-11-16 12:57:13 +02001342 reset_control_assert(ddata->rsts);
1343
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001344 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001345}
1346
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001347static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001348{
1349 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001350 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001351
1352 ddata = dev_get_drvdata(dev);
1353
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001354 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001355 return 0;
1356
Tony Lindgren8383e252019-05-27 04:51:56 -07001357
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001358 sysc_clkdm_deny_idle(ddata);
1359
Tony Lindgrend8789702019-03-21 11:00:21 -07001360 if (sysc_opt_clks_needed(ddata)) {
1361 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001362 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001363 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001364 }
1365
Tony Lindgrend8789702019-03-21 11:00:21 -07001366 error = sysc_enable_main_clocks(ddata);
1367 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001368 goto err_opt_clocks;
1369
Tero Kristobf59ebb2019-10-07 15:29:29 +03001370 reset_control_deassert(ddata->rsts);
1371
Tony Lindgren93de83a2019-03-21 11:00:21 -07001372 if (ddata->legacy_mode) {
1373 error = sysc_runtime_resume_legacy(dev, ddata);
1374 if (error)
1375 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001376 } else {
1377 error = sysc_enable_module(dev);
1378 if (error)
1379 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001380 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001381
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001382 ddata->enabled = true;
1383
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001384 sysc_clkdm_allow_idle(ddata);
1385
Tony Lindgrend8789702019-03-21 11:00:21 -07001386 return 0;
1387
1388err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001389 sysc_disable_main_clocks(ddata);
1390err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001391 if (sysc_opt_clks_needed(ddata))
1392 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001393err_allow_idle:
1394 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001395
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001396 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001397}
1398
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001399/*
1400 * Checks if device context was lost. Assumes the sysconfig register value
1401 * after lost context is different from the configured value. Only works for
1402 * enabled devices.
1403 *
1404 * Eventually we may want to also add support to using the context lost
1405 * registers that some SoCs have.
1406 */
1407static int sysc_check_context(struct sysc *ddata)
1408{
1409 u32 reg;
1410
1411 if (!ddata->enabled)
1412 return -ENODATA;
1413
1414 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1415 if (reg == ddata->sysconfig)
1416 return 0;
1417
1418 return -EACCES;
1419}
1420
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001421static int sysc_reinit_module(struct sysc *ddata, bool leave_enabled)
1422{
1423 struct device *dev = ddata->dev;
1424 int error;
1425
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001426 if (ddata->enabled) {
Tony Lindgren95ec14fa2021-09-21 12:42:25 +03001427 /* Nothing to do if enabled and context not lost */
1428 error = sysc_check_context(ddata);
1429 if (!error)
1430 return 0;
1431
1432 /* Disable target module if it is enabled */
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001433 error = sysc_runtime_suspend(dev);
1434 if (error)
1435 dev_warn(dev, "reinit suspend failed: %i\n", error);
1436 }
1437
1438 /* Enable target module */
1439 error = sysc_runtime_resume(dev);
1440 if (error)
1441 dev_warn(dev, "reinit resume failed: %i\n", error);
1442
1443 if (leave_enabled)
1444 return error;
1445
1446 /* Disable target module if no leave_enabled was set */
1447 error = sysc_runtime_suspend(dev);
1448 if (error)
1449 dev_warn(dev, "reinit suspend failed: %i\n", error);
1450
1451 return error;
1452}
1453
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001454static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001455{
1456 struct sysc *ddata;
1457
1458 ddata = dev_get_drvdata(dev);
1459
Tony Lindgrena55de412020-07-02 13:57:14 -07001460 if (ddata->cfg.quirks &
1461 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
Tony Lindgrene7420c22018-04-16 10:26:46 -07001462 return 0;
1463
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001464 if (!ddata->enabled)
1465 return 0;
1466
1467 ddata->needs_resume = 1;
1468
1469 return sysc_runtime_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001470}
1471
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001472static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001473{
1474 struct sysc *ddata;
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001475 int error = 0;
Tony Lindgren62020f22018-02-22 13:59:44 -08001476
1477 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001478
Tony Lindgrena55de412020-07-02 13:57:14 -07001479 if (ddata->cfg.quirks &
1480 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
Tony Lindgrene7420c22018-04-16 10:26:46 -07001481 return 0;
1482
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001483 if (ddata->cfg.quirks & SYSC_QUIRK_REINIT_ON_RESUME) {
1484 error = sysc_reinit_module(ddata, ddata->needs_resume);
1485 if (error)
1486 dev_warn(dev, "noirq_resume failed: %i\n", error);
1487 } else if (ddata->needs_resume) {
1488 error = sysc_runtime_resume(dev);
1489 if (error)
1490 dev_warn(dev, "noirq_resume failed: %i\n", error);
1491 }
1492
1493 ddata->needs_resume = 0;
1494
1495 return error;
Tony Lindgrene7420c22018-04-16 10:26:46 -07001496}
1497
Tony Lindgren0eecc632017-10-10 14:23:43 -07001498static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001499 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001500 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1501 sysc_runtime_resume,
1502 NULL)
1503};
1504
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001505/* Module revision register based quirks */
1506struct sysc_revision_quirk {
1507 const char *name;
1508 u32 base;
1509 int rev_offset;
1510 int sysc_offset;
1511 int syss_offset;
1512 u32 revision;
1513 u32 revision_mask;
1514 u32 quirks;
1515};
1516
1517#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1518 optrev_val, optrevmask, optquirkmask) \
1519 { \
1520 .name = (optname), \
1521 .base = (optbase), \
1522 .rev_offset = (optrev), \
1523 .sysc_offset = (optsysc), \
1524 .syss_offset = (optsyss), \
1525 .revision = (optrev_val), \
1526 .revision_mask = (optrevmask), \
1527 .quirks = (optquirkmask), \
1528 }
1529
1530static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1531 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001532 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -07001533 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001534 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1535 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001536 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1537 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001538 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001539 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001540 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001541 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001542 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001543 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001544 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001545
Tony Lindgrena54275f2019-03-21 11:00:21 -07001546 /* Quirks that need to be set based on the module address */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001547 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -ENODEV, 0x50000800, 0xffffffff,
Tony Lindgrena54275f2019-03-21 11:00:21 -07001548 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1549 SYSC_QUIRK_SWSUP_SIDLE),
1550
Tony Lindgren4e23be42019-06-10 04:48:05 -07001551 /* Quirks that need to be set based on detected module */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001552 SYSC_QUIRK("aess", 0, 0, 0x10, -ENODEV, 0x40000000, 0xffffffff,
Tony Lindgren020003f2019-11-14 08:25:28 -08001553 SYSC_MODULE_QUIRK_AESS),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001554 SYSC_QUIRK("dcan", 0x48480000, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001555 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001556 SYSC_QUIRK("dss", 0x4832a000, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001557 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001558 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000040, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001559 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001560 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000061, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001561 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001562 SYSC_QUIRK("dwc3", 0x48880000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001563 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001564 SYSC_QUIRK("dwc3", 0x488c0000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001565 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgrencfeeea62020-11-16 12:57:13 +02001566 SYSC_QUIRK("gpmc", 0, 0, 0x10, 0x14, 0x00000060, 0xffffffff,
1567 SYSC_QUIRK_GPMC_DEBUG),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001568 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50030200, 0xffffffff,
1569 SYSC_QUIRK_OPT_CLKS_NEEDED),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001570 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001571 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001572 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001573 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001574 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001575 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001576 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001577 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001578 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001579 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001580 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
Tony Lindgrene275d212020-10-26 10:08:47 +02001581 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001582 SYSC_QUIRK("gpu", 0x50000000, 0x14, -ENODEV, -ENODEV, 0x00010201, 0xffffffff, 0),
1583 SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff,
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001584 SYSC_MODULE_QUIRK_SGX),
Tony Lindgrenaef067e2020-03-10 09:06:02 -07001585 SYSC_QUIRK("lcdc", 0, 0, 0x54, -ENODEV, 0x4f201000, 0xffffffff,
1586 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Peter Ujfalusi8122dc52021-07-17 15:09:24 +03001587 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44306302, 0xffffffff,
1588 SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgrene8639e12020-02-24 12:58:03 -08001589 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -ENODEV, 0x4eb01908, 0xffff00f0,
1590 SYSC_MODULE_QUIRK_RTC_UNLOCK),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001591 SYSC_QUIRK("tptc", 0, 0, 0x10, -ENODEV, 0x40006c00, 0xffffefff,
1592 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1593 SYSC_QUIRK("tptc", 0, 0, -ENODEV, -ENODEV, 0x40007c00, 0xffffffff,
1594 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgrendb8e7122021-05-07 12:09:03 +03001595 SYSC_QUIRK("sata", 0, 0xfc, 0x1100, -ENODEV, 0x5e412000, 0xffffffff,
1596 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren42546322020-07-13 09:59:47 -07001597 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff,
1598 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1599 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -ENODEV, 0x50700101, 0xffffffff,
1600 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren03856e92019-10-21 13:36:09 -07001601 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1602 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001603 SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -ENODEV, 0x4ea2080d, 0xffffffff,
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001604 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
1605 SYSC_QUIRK_REINIT_ON_RESUME),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001606 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1607 SYSC_MODULE_QUIRK_WDT),
Suman Annab2745d92020-02-27 16:28:34 -06001608 /* PRUSS on am3, am4 and am5 */
1609 SYSC_QUIRK("pruss", 0, 0x26000, 0x26004, -ENODEV, 0x47000000, 0xff000000,
1610 SYSC_MODULE_QUIRK_PRUSS),
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001611 /* Watchdog on am3 and am4 */
1612 SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1613 SYSC_MODULE_QUIRK_WDT | SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001614
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001615#ifdef DEBUG
Tony Lindgren590e15c2020-02-24 12:58:03 -08001616 SYSC_QUIRK("adc", 0, 0, 0x10, -ENODEV, 0x47300001, 0xffffffff, 0),
1617 SYSC_QUIRK("atl", 0, 0, -ENODEV, -ENODEV, 0x0a070100, 0xffffffff, 0),
1618 SYSC_QUIRK("cm", 0, 0, -ENODEV, -ENODEV, 0x40000301, 0xffffffff, 0),
1619 SYSC_QUIRK("control", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001620 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001621 0xffff00f0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001622 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff, 0),
1623 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001624 SYSC_QUIRK("dispc", 0x4832a400, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1625 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1626 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000051, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001627 SYSC_QUIRK("dmic", 0, 0, 0x10, -ENODEV, 0x50010000, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001628 SYSC_QUIRK("dsi", 0x58004000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1629 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1630 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1631 SYSC_QUIRK("dsi", 0x58009000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001632 SYSC_QUIRK("dwc3", 0, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, 0),
Tony Lindgren7edd00f2019-08-14 05:18:16 -07001633 SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1634 SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001635 SYSC_QUIRK("elm", 0x48080000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
1636 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x40441403, 0xffff0fff, 0),
1637 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x50440500, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001638 SYSC_QUIRK("epwmss", 0, 0, 0x4, -ENODEV, 0x47400001, 0xffffffff, 0),
1639 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -ENODEV, 0, 0, 0),
1640 SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001641 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50031d00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001642 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001643 SYSC_QUIRK("iss", 0, 0, 0x10, -ENODEV, 0x40000101, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001644 SYSC_QUIRK("keypad", 0x4a31c000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001645 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44307b02, 0xffffffff, 0),
1646 SYSC_QUIRK("mcbsp", 0, -ENODEV, 0x8c, -ENODEV, 0, 0, 0),
1647 SYSC_QUIRK("mcspi", 0, 0, 0x10, -ENODEV, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001648 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001649 SYSC_QUIRK("mailbox", 0, 0, 0x10, -ENODEV, 0x00000400, 0xffffffff, 0),
1650 SYSC_QUIRK("m3", 0, 0, -ENODEV, -ENODEV, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001651 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001652 SYSC_QUIRK("ocp2scp", 0, 0, -ENODEV, -ENODEV, 0x50060007, 0xffffffff, 0),
1653 SYSC_QUIRK("padconf", 0, 0, 0x10, -ENODEV, 0x4fff0800, 0xffffffff, 0),
1654 SYSC_QUIRK("padconf", 0, 0, -ENODEV, -ENODEV, 0x40001100, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001655 SYSC_QUIRK("pcie", 0x51000000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
1656 SYSC_QUIRK("pcie", 0x51800000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001657 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000100, 0xffffffff, 0),
1658 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x00004102, 0xffffffff, 0),
1659 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000400, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001660 SYSC_QUIRK("rfbi", 0x4832a800, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1661 SYSC_QUIRK("rfbi", 0x58002000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001662 SYSC_QUIRK("scm", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
1663 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4e8b0100, 0xffffffff, 0),
1664 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4f000100, 0xffffffff, 0),
1665 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x40000900, 0xffffffff, 0),
1666 SYSC_QUIRK("scrm", 0, 0, -ENODEV, -ENODEV, 0x00000010, 0xffffffff, 0),
1667 SYSC_QUIRK("sdio", 0, 0, 0x10, -ENODEV, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001668 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001669 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001670 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40000902, 0xffffffff, 0),
1671 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40002903, 0xffffffff, 0),
Tony Lindgrened4520d2021-08-09 11:27:47 -05001672 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x24, -ENODEV, 0x00000000, 0xffffffff, 0),
1673 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x38, -ENODEV, 0x00000000, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001674 SYSC_QUIRK("spinlock", 0, 0, 0x10, -ENODEV, 0x50020000, 0xffffffff, 0),
1675 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -ENODEV, 0x00000020, 0xffffffff, 0),
Tony Lindgren1a542812020-05-07 09:43:08 -07001676 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000013, 0xffffffff, 0),
1677 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff, 0),
1678 /* Some timers on omap4 and later */
1679 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x50002100, 0xffffffff, 0),
1680 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x4fff1301, 0xffff00ff, 0),
1681 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000040, 0xffffffff, 0),
1682 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000011, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001683 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000060, 0xffffffff, 0),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001684 SYSC_QUIRK("tpcc", 0, 0, -ENODEV, -ENODEV, 0x40014c00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001685 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001686 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001687 SYSC_QUIRK("venc", 0x58003000, 0, -ENODEV, -ENODEV, 0x00000002, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001688 SYSC_QUIRK("vfpe", 0, 0, 0x104, -ENODEV, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001689#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001690};
1691
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001692/*
1693 * Early quirks based on module base and register offsets only that are
1694 * needed before the module revision can be read
1695 */
1696static void sysc_init_early_quirks(struct sysc *ddata)
1697{
1698 const struct sysc_revision_quirk *q;
1699 int i;
1700
1701 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1702 q = &sysc_revision_quirks[i];
1703
1704 if (!q->base)
1705 continue;
1706
1707 if (q->base != ddata->module_pa)
1708 continue;
1709
Tony Lindgren590e15c2020-02-24 12:58:03 -08001710 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001711 continue;
1712
Tony Lindgren590e15c2020-02-24 12:58:03 -08001713 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001714 continue;
1715
Tony Lindgren590e15c2020-02-24 12:58:03 -08001716 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001717 continue;
1718
1719 ddata->name = q->name;
1720 ddata->cfg.quirks |= q->quirks;
1721 }
1722}
1723
1724/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001725static void sysc_init_revision_quirks(struct sysc *ddata)
1726{
1727 const struct sysc_revision_quirk *q;
1728 int i;
1729
1730 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1731 q = &sysc_revision_quirks[i];
1732
1733 if (q->base && q->base != ddata->module_pa)
1734 continue;
1735
Tony Lindgren590e15c2020-02-24 12:58:03 -08001736 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001737 continue;
1738
Tony Lindgren590e15c2020-02-24 12:58:03 -08001739 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001740 continue;
1741
Tony Lindgren590e15c2020-02-24 12:58:03 -08001742 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001743 continue;
1744
1745 if (q->revision == ddata->revision ||
1746 (q->revision & q->revision_mask) ==
1747 (ddata->revision & q->revision_mask)) {
1748 ddata->name = q->name;
1749 ddata->cfg.quirks |= q->quirks;
1750 }
1751 }
1752}
1753
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001754/*
1755 * DSS needs dispc outputs disabled to reset modules. Returns mask of
1756 * enabled DSS interrupts. Eventually we may be able to do this on
1757 * dispc init rather than top-level DSS init.
1758 */
1759static u32 sysc_quirk_dispc(struct sysc *ddata, int dispc_offset,
1760 bool disable)
1761{
1762 bool lcd_en, digit_en, lcd2_en = false, lcd3_en = false;
1763 const int lcd_en_mask = BIT(0), digit_en_mask = BIT(1);
1764 int manager_count;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001765 bool framedonetv_irq = true;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001766 u32 val, irq_mask = 0;
1767
1768 switch (sysc_soc->soc) {
1769 case SOC_2420 ... SOC_3630:
1770 manager_count = 2;
1771 framedonetv_irq = false;
1772 break;
1773 case SOC_4430 ... SOC_4470:
1774 manager_count = 3;
1775 break;
1776 case SOC_5430:
1777 case SOC_DRA7:
1778 manager_count = 4;
1779 break;
1780 case SOC_AM4:
1781 manager_count = 1;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001782 framedonetv_irq = false;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001783 break;
1784 case SOC_UNKNOWN:
1785 default:
1786 return 0;
Yang Li52fbb5a2021-02-02 15:00:05 +08001787 }
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001788
1789 /* Remap the whole module range to be able to reset dispc outputs */
1790 devm_iounmap(ddata->dev, ddata->module_va);
1791 ddata->module_va = devm_ioremap(ddata->dev,
1792 ddata->module_pa,
1793 ddata->module_size);
1794 if (!ddata->module_va)
1795 return -EIO;
1796
1797 /* DISP_CONTROL */
1798 val = sysc_read(ddata, dispc_offset + 0x40);
1799 lcd_en = val & lcd_en_mask;
1800 digit_en = val & digit_en_mask;
1801 if (lcd_en)
1802 irq_mask |= BIT(0); /* FRAMEDONE */
1803 if (digit_en) {
1804 if (framedonetv_irq)
1805 irq_mask |= BIT(24); /* FRAMEDONETV */
1806 else
1807 irq_mask |= BIT(2) | BIT(3); /* EVSYNC bits */
1808 }
1809 if (disable & (lcd_en | digit_en))
1810 sysc_write(ddata, dispc_offset + 0x40,
1811 val & ~(lcd_en_mask | digit_en_mask));
1812
1813 if (manager_count <= 2)
1814 return irq_mask;
1815
1816 /* DISPC_CONTROL2 */
1817 val = sysc_read(ddata, dispc_offset + 0x238);
1818 lcd2_en = val & lcd_en_mask;
1819 if (lcd2_en)
1820 irq_mask |= BIT(22); /* FRAMEDONE2 */
1821 if (disable && lcd2_en)
1822 sysc_write(ddata, dispc_offset + 0x238,
1823 val & ~lcd_en_mask);
1824
1825 if (manager_count <= 3)
1826 return irq_mask;
1827
1828 /* DISPC_CONTROL3 */
1829 val = sysc_read(ddata, dispc_offset + 0x848);
1830 lcd3_en = val & lcd_en_mask;
1831 if (lcd3_en)
1832 irq_mask |= BIT(30); /* FRAMEDONE3 */
1833 if (disable && lcd3_en)
1834 sysc_write(ddata, dispc_offset + 0x848,
1835 val & ~lcd_en_mask);
1836
1837 return irq_mask;
1838}
1839
1840/* DSS needs child outputs disabled and SDI registers cleared for reset */
1841static void sysc_pre_reset_quirk_dss(struct sysc *ddata)
1842{
1843 const int dispc_offset = 0x1000;
1844 int error;
1845 u32 irq_mask, val;
1846
1847 /* Get enabled outputs */
1848 irq_mask = sysc_quirk_dispc(ddata, dispc_offset, false);
1849 if (!irq_mask)
1850 return;
1851
1852 /* Clear IRQSTATUS */
Tony Lindgren69e60902020-03-03 07:17:43 -08001853 sysc_write(ddata, dispc_offset + 0x18, irq_mask);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001854
1855 /* Disable outputs */
1856 val = sysc_quirk_dispc(ddata, dispc_offset, true);
1857
1858 /* Poll IRQSTATUS */
1859 error = readl_poll_timeout(ddata->module_va + dispc_offset + 0x18,
1860 val, val != irq_mask, 100, 50);
1861 if (error)
1862 dev_warn(ddata->dev, "%s: timed out %08x !+ %08x\n",
1863 __func__, val, irq_mask);
1864
1865 if (sysc_soc->soc == SOC_3430) {
1866 /* Clear DSS_SDI_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001867 sysc_write(ddata, 0x44, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001868
1869 /* Clear DSS_PLL_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001870 sysc_write(ddata, 0x48, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001871 }
1872
1873 /* Clear DSS_CONTROL to switch DSS clock sources to PRCM if not */
Tony Lindgren69e60902020-03-03 07:17:43 -08001874 sysc_write(ddata, 0x40, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001875}
1876
Tony Lindgren4e23be42019-06-10 04:48:05 -07001877/* 1-wire needs module's internal clocks enabled for reset */
Tony Lindgrenaec551c2020-02-24 12:58:03 -08001878static void sysc_pre_reset_quirk_hdq1w(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001879{
1880 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1881 u16 val;
1882
1883 val = sysc_read(ddata, offset);
1884 val |= BIT(5);
1885 sysc_write(ddata, offset, val);
1886}
1887
Tony Lindgren020003f2019-11-14 08:25:28 -08001888/* AESS (Audio Engine SubSystem) needs autogating set after enable */
1889static void sysc_module_enable_quirk_aess(struct sysc *ddata)
1890{
1891 int offset = 0x7c; /* AESS_AUTO_GATING_ENABLE */
1892
1893 sysc_write(ddata, offset, 1);
1894}
1895
Tony Lindgrene64c0212020-02-24 12:58:03 -08001896/* I2C needs to be disabled for reset */
Tony Lindgren4e23be42019-06-10 04:48:05 -07001897static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1898{
1899 int offset;
1900 u16 val;
1901
1902 /* I2C_CON, omap2/3 is different from omap4 and later */
1903 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1904 offset = 0x24;
1905 else
1906 offset = 0xa4;
1907
1908 /* I2C_EN */
1909 val = sysc_read(ddata, offset);
1910 if (enable)
1911 val |= BIT(15);
1912 else
1913 val &= ~BIT(15);
1914 sysc_write(ddata, offset, val);
1915}
1916
Tony Lindgrene64c0212020-02-24 12:58:03 -08001917static void sysc_pre_reset_quirk_i2c(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001918{
1919 sysc_clk_quirk_i2c(ddata, false);
1920}
1921
Tony Lindgrene64c0212020-02-24 12:58:03 -08001922static void sysc_post_reset_quirk_i2c(struct sysc *ddata)
1923{
1924 sysc_clk_quirk_i2c(ddata, true);
1925}
1926
Tony Lindgrene8639e12020-02-24 12:58:03 -08001927/* RTC on am3 and 4 needs to be unlocked and locked for sysconfig */
1928static void sysc_quirk_rtc(struct sysc *ddata, bool lock)
1929{
1930 u32 val, kick0_val = 0, kick1_val = 0;
1931 unsigned long flags;
1932 int error;
1933
1934 if (!lock) {
1935 kick0_val = 0x83e70b13;
1936 kick1_val = 0x95a4f1e0;
1937 }
1938
1939 local_irq_save(flags);
1940 /* RTC_STATUS BUSY bit may stay active for 1/32768 seconds (~30 usec) */
Tony Lindgrenafe6f1e2020-07-02 10:41:02 -07001941 error = readl_poll_timeout_atomic(ddata->module_va + 0x44, val,
1942 !(val & BIT(0)), 100, 50);
Tony Lindgrene8639e12020-02-24 12:58:03 -08001943 if (error)
1944 dev_warn(ddata->dev, "rtc busy timeout\n");
1945 /* Now we have ~15 microseconds to read/write various registers */
1946 sysc_write(ddata, 0x6c, kick0_val);
1947 sysc_write(ddata, 0x70, kick1_val);
1948 local_irq_restore(flags);
1949}
1950
1951static void sysc_module_unlock_quirk_rtc(struct sysc *ddata)
1952{
1953 sysc_quirk_rtc(ddata, false);
1954}
1955
1956static void sysc_module_lock_quirk_rtc(struct sysc *ddata)
1957{
1958 sysc_quirk_rtc(ddata, true);
1959}
1960
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001961/* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */
1962static void sysc_module_enable_quirk_sgx(struct sysc *ddata)
1963{
1964 int offset = 0xff08; /* OCP_DEBUG_CONFIG */
1965 u32 val = BIT(31); /* THALIA_INT_BYPASS */
1966
1967 sysc_write(ddata, offset, val);
1968}
1969
Tony Lindgren4e23be42019-06-10 04:48:05 -07001970/* Watchdog timer needs a disable sequence after reset */
1971static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1972{
1973 int wps, spr, error;
1974 u32 val;
1975
1976 wps = 0x34;
1977 spr = 0x48;
1978
1979 sysc_write(ddata, spr, 0xaaaa);
1980 error = readl_poll_timeout(ddata->module_va + wps, val,
1981 !(val & 0x10), 100,
1982 MAX_MODULE_SOFTRESET_WAIT);
1983 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001984 dev_warn(ddata->dev, "wdt disable step1 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001985
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001986 sysc_write(ddata, spr, 0x5555);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001987 error = readl_poll_timeout(ddata->module_va + wps, val,
1988 !(val & 0x10), 100,
1989 MAX_MODULE_SOFTRESET_WAIT);
1990 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001991 dev_warn(ddata->dev, "wdt disable step2 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001992}
1993
Suman Annab2745d92020-02-27 16:28:34 -06001994/* PRUSS needs to set MSTANDBY_INIT inorder to idle properly */
1995static void sysc_module_disable_quirk_pruss(struct sysc *ddata)
1996{
1997 u32 reg;
1998
1999 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
2000 reg |= SYSC_PRUSS_STANDBY_INIT;
2001 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
2002}
2003
Tony Lindgren4e23be42019-06-10 04:48:05 -07002004static void sysc_init_module_quirks(struct sysc *ddata)
2005{
2006 if (ddata->legacy_mode || !ddata->name)
2007 return;
2008
2009 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08002010 ddata->pre_reset_quirk = sysc_pre_reset_quirk_hdq1w;
Tony Lindgren4e23be42019-06-10 04:48:05 -07002011
2012 return;
2013 }
2014
Tony Lindgrencfeeea62020-11-16 12:57:13 +02002015#ifdef CONFIG_OMAP_GPMC_DEBUG
2016 if (ddata->cfg.quirks & SYSC_QUIRK_GPMC_DEBUG) {
2017 ddata->cfg.quirks |= SYSC_QUIRK_NO_RESET_ON_INIT;
2018
2019 return;
2020 }
2021#endif
2022
Tony Lindgren4e23be42019-06-10 04:48:05 -07002023 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08002024 ddata->pre_reset_quirk = sysc_pre_reset_quirk_i2c;
2025 ddata->post_reset_quirk = sysc_post_reset_quirk_i2c;
Tony Lindgren4e23be42019-06-10 04:48:05 -07002026
2027 return;
2028 }
2029
Tony Lindgren020003f2019-11-14 08:25:28 -08002030 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_AESS)
2031 ddata->module_enable_quirk = sysc_module_enable_quirk_aess;
2032
Tony Lindgren7324a7a2020-02-24 12:58:03 -08002033 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_DSS_RESET)
2034 ddata->pre_reset_quirk = sysc_pre_reset_quirk_dss;
2035
Tony Lindgrene8639e12020-02-24 12:58:03 -08002036 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_RTC_UNLOCK) {
2037 ddata->module_unlock_quirk = sysc_module_unlock_quirk_rtc;
2038 ddata->module_lock_quirk = sysc_module_lock_quirk_rtc;
2039
2040 return;
2041 }
2042
Tony Lindgrend7f563d2019-08-14 05:18:16 -07002043 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_SGX)
2044 ddata->module_enable_quirk = sysc_module_enable_quirk_sgx;
2045
Tony Lindgrenc7d86692019-10-17 11:21:44 -07002046 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT) {
Tony Lindgren4e23be42019-06-10 04:48:05 -07002047 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
Tony Lindgrenc7d86692019-10-17 11:21:44 -07002048 ddata->module_disable_quirk = sysc_reset_done_quirk_wdt;
2049 }
Suman Annab2745d92020-02-27 16:28:34 -06002050
2051 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_PRUSS)
2052 ddata->module_disable_quirk = sysc_module_disable_quirk_pruss;
Tony Lindgren4e23be42019-06-10 04:48:05 -07002053}
2054
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002055static int sysc_clockdomain_init(struct sysc *ddata)
2056{
2057 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2058 struct clk *fck = NULL, *ick = NULL;
2059 int error;
2060
2061 if (!pdata || !pdata->init_clockdomain)
2062 return 0;
2063
2064 switch (ddata->nr_clocks) {
2065 case 2:
2066 ick = ddata->clocks[SYSC_ICK];
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002067 fallthrough;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002068 case 1:
2069 fck = ddata->clocks[SYSC_FCK];
2070 break;
2071 case 0:
2072 return 0;
2073 }
2074
2075 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
2076 if (!error || error == -ENODEV)
2077 return 0;
2078
2079 return error;
2080}
2081
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002082/*
2083 * Note that pdata->init_module() typically does a reset first. After
2084 * pdata->init_module() is done, PM runtime can be used for the interconnect
2085 * target module.
2086 */
2087static int sysc_legacy_init(struct sysc *ddata)
2088{
2089 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2090 int error;
2091
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002092 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002093 return 0;
2094
2095 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
2096 if (error == -EEXIST)
2097 error = 0;
2098
2099 return error;
2100}
2101
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002102/*
2103 * Note that the caller must ensure the interconnect target module is enabled
2104 * before calling reset. Otherwise reset will not complete.
2105 */
Faiz Abbas596e7952018-07-09 22:18:39 +05302106static int sysc_reset(struct sysc *ddata)
2107{
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002108 int sysc_offset, sysc_val, error;
2109 u32 sysc_mask;
Faiz Abbas596e7952018-07-09 22:18:39 +05302110
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002111 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002112
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002113 if (ddata->legacy_mode ||
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002114 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05302115 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
2116 return 0;
2117
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002118 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05302119
Tony Lindgrene64c0212020-02-24 12:58:03 -08002120 if (ddata->pre_reset_quirk)
2121 ddata->pre_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002122
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002123 if (sysc_offset >= 0) {
2124 sysc_val = sysc_read_sysconfig(ddata);
2125 sysc_val |= sysc_mask;
2126 sysc_write(ddata, sysc_offset, sysc_val);
2127 }
Faiz Abbas596e7952018-07-09 22:18:39 +05302128
Tony Lindgrene709ed72019-12-12 08:20:10 -08002129 if (ddata->cfg.srst_udelay)
2130 usleep_range(ddata->cfg.srst_udelay,
2131 ddata->cfg.srst_udelay * 2);
2132
Tony Lindgrene64c0212020-02-24 12:58:03 -08002133 if (ddata->post_reset_quirk)
2134 ddata->post_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002135
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002136 error = sysc_wait_softreset(ddata);
2137 if (error)
2138 dev_warn(ddata->dev, "OCP softreset timed out\n");
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002139
Tony Lindgren4e23be42019-06-10 04:48:05 -07002140 if (ddata->reset_done_quirk)
2141 ddata->reset_done_quirk(ddata);
2142
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002143 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05302144}
2145
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002146/*
2147 * At this point the module is configured enough to read the revision but
2148 * module may not be completely configured yet to use PM runtime. Enable
2149 * all clocks directly during init to configure the quirks needed for PM
2150 * runtime based on the revision register.
2151 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08002152static int sysc_init_module(struct sysc *ddata)
2153{
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002154 bool rstctrl_deasserted = false;
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002155 int error = 0;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002156
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002157 error = sysc_clockdomain_init(ddata);
2158 if (error)
2159 return error;
2160
Tony Lindgrend0989132019-09-05 07:37:22 -07002161 sysc_clkdm_deny_idle(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002162
Tony Lindgrend0989132019-09-05 07:37:22 -07002163 /*
2164 * Always enable clocks. The bootloader may or may not have enabled
2165 * the related clocks.
2166 */
2167 error = sysc_enable_opt_clocks(ddata);
2168 if (error)
2169 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002170
Tony Lindgrend0989132019-09-05 07:37:22 -07002171 error = sysc_enable_main_clocks(ddata);
2172 if (error)
2173 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05302174
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002175 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
Tero Kristodf4f3452019-10-07 15:29:30 +03002176 error = reset_control_deassert(ddata->rsts);
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002177 if (error)
2178 goto err_main_clocks;
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002179 rstctrl_deasserted = true;
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002180 }
2181
Tony Lindgren566a9b052017-12-15 09:41:19 -08002182 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002183 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002184 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002185
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002186 if (ddata->legacy_mode) {
2187 error = sysc_legacy_init(ddata);
2188 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002189 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002190 }
2191
Tony Lindgrend0989132019-09-05 07:37:22 -07002192 if (!ddata->legacy_mode) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002193 error = sysc_enable_module(ddata->dev);
2194 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002195 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002196 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002197
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002198 error = sysc_reset(ddata);
2199 if (error)
2200 dev_err(ddata->dev, "Reset failed with %d\n", error);
2201
Tero Kristocdc56c12019-10-07 15:29:31 +03002202 if (error && !ddata->legacy_mode)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002203 sysc_disable_module(ddata->dev);
2204
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002205err_main_clocks:
Tero Kristocdc56c12019-10-07 15:29:31 +03002206 if (error)
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002207 sysc_disable_main_clocks(ddata);
2208err_opt_clocks:
Tony Lindgrend0989132019-09-05 07:37:22 -07002209 /* No re-enable of clockdomain autoidle to prevent module autoidle */
Tero Kristocdc56c12019-10-07 15:29:31 +03002210 if (error) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002211 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002212 sysc_clkdm_allow_idle(ddata);
2213 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002214
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002215 if (error && rstctrl_deasserted &&
2216 !(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
2217 reset_control_assert(ddata->rsts);
2218
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002219 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002220}
2221
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002222static int sysc_init_sysc_mask(struct sysc *ddata)
2223{
2224 struct device_node *np = ddata->dev->of_node;
2225 int error;
2226 u32 val;
2227
2228 error = of_property_read_u32(np, "ti,sysc-mask", &val);
2229 if (error)
2230 return 0;
2231
Tony Lindgrene212abd2019-07-22 03:44:52 -07002232 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002233
2234 return 0;
2235}
2236
2237static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
2238 const char *name)
2239{
2240 struct device_node *np = ddata->dev->of_node;
2241 struct property *prop;
2242 const __be32 *p;
2243 u32 val;
2244
2245 of_property_for_each_u32(np, name, prop, p, val) {
2246 if (val >= SYSC_NR_IDLEMODES) {
2247 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
2248 return -EINVAL;
2249 }
2250 *idlemodes |= (1 << val);
2251 }
2252
2253 return 0;
2254}
2255
2256static int sysc_init_idlemodes(struct sysc *ddata)
2257{
2258 int error;
2259
2260 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
2261 "ti,sysc-midle");
2262 if (error)
2263 return error;
2264
2265 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
2266 "ti,sysc-sidle");
2267 if (error)
2268 return error;
2269
2270 return 0;
2271}
2272
2273/*
2274 * Only some devices on omap4 and later have SYSCONFIG reset done
2275 * bit. We can detect this if there is no SYSSTATUS at all, or the
2276 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
2277 * have multiple bits for the child devices like OHCI and EHCI.
2278 * Depends on SYSC being parsed first.
2279 */
2280static int sysc_init_syss_mask(struct sysc *ddata)
2281{
2282 struct device_node *np = ddata->dev->of_node;
2283 int error;
2284 u32 val;
2285
2286 error = of_property_read_u32(np, "ti,syss-mask", &val);
2287 if (error) {
2288 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
2289 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
2290 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2291 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2292
2293 return 0;
2294 }
2295
2296 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2297 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2298
2299 ddata->cfg.syss_mask = val;
2300
2301 return 0;
2302}
2303
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002304/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002305 * Many child device drivers need to have fck and opt clocks available
2306 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002307 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002308static int sysc_child_add_named_clock(struct sysc *ddata,
2309 struct device *child,
2310 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002311{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002312 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002313 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002314 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002315
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002316 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002317 return 0;
2318
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002319 clk = clk_get(child, name);
2320 if (!IS_ERR(clk)) {
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002321 error = -EEXIST;
2322 goto put_clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002323 }
2324
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002325 clk = clk_get(ddata->dev, name);
2326 if (IS_ERR(clk))
2327 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002328
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002329 l = clkdev_create(clk, name, dev_name(child));
2330 if (!l)
2331 error = -ENOMEM;
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002332put_clk:
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002333 clk_put(clk);
2334
2335 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002336}
2337
Tony Lindgren09dfe582018-04-16 10:25:52 -07002338static int sysc_child_add_clocks(struct sysc *ddata,
2339 struct device *child)
2340{
2341 int i, error;
2342
2343 for (i = 0; i < ddata->nr_clocks; i++) {
2344 error = sysc_child_add_named_clock(ddata,
2345 child,
2346 ddata->clock_roles[i]);
2347 if (error && error != -EEXIST) {
2348 dev_err(ddata->dev, "could not add child clock %s: %i\n",
2349 ddata->clock_roles[i], error);
2350
2351 return error;
2352 }
2353 }
2354
2355 return 0;
2356}
2357
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002358static struct device_type sysc_device_type = {
2359};
2360
2361static struct sysc *sysc_child_to_parent(struct device *dev)
2362{
2363 struct device *parent = dev->parent;
2364
2365 if (!parent || parent->type != &sysc_device_type)
2366 return NULL;
2367
2368 return dev_get_drvdata(parent);
2369}
2370
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002371static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
2372{
2373 struct sysc *ddata;
2374 int error;
2375
2376 ddata = sysc_child_to_parent(dev);
2377
2378 error = pm_generic_runtime_suspend(dev);
2379 if (error)
2380 return error;
2381
2382 if (!ddata->enabled)
2383 return 0;
2384
2385 return sysc_runtime_suspend(ddata->dev);
2386}
2387
2388static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
2389{
2390 struct sysc *ddata;
2391 int error;
2392
2393 ddata = sysc_child_to_parent(dev);
2394
2395 if (!ddata->enabled) {
2396 error = sysc_runtime_resume(ddata->dev);
2397 if (error < 0)
2398 dev_err(ddata->dev,
2399 "%s error: %i\n", __func__, error);
2400 }
2401
2402 return pm_generic_runtime_resume(dev);
2403}
2404
2405#ifdef CONFIG_PM_SLEEP
2406static int sysc_child_suspend_noirq(struct device *dev)
2407{
2408 struct sysc *ddata;
2409 int error;
2410
2411 ddata = sysc_child_to_parent(dev);
2412
Tony Lindgrenef55f822018-04-16 10:27:15 -07002413 dev_dbg(ddata->dev, "%s %s\n", __func__,
2414 ddata->name ? ddata->name : "");
2415
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002416 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002417 if (error) {
2418 dev_err(dev, "%s error at %i: %i\n",
2419 __func__, __LINE__, error);
2420
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002421 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002422 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002423
2424 if (!pm_runtime_status_suspended(dev)) {
2425 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002426 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07002427 dev_dbg(dev, "%s busy at %i: %i\n",
2428 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002429
Tony Lindgren4f3530f2018-08-08 01:07:06 -07002430 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002431 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002432
2433 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002434 if (error) {
2435 dev_err(dev, "%s error at %i: %i\n",
2436 __func__, __LINE__, error);
2437
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002438 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002439 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002440
2441 ddata->child_needs_resume = true;
2442 }
2443
2444 return 0;
2445}
2446
2447static int sysc_child_resume_noirq(struct device *dev)
2448{
2449 struct sysc *ddata;
2450 int error;
2451
2452 ddata = sysc_child_to_parent(dev);
2453
Tony Lindgrenef55f822018-04-16 10:27:15 -07002454 dev_dbg(ddata->dev, "%s %s\n", __func__,
2455 ddata->name ? ddata->name : "");
2456
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002457 if (ddata->child_needs_resume) {
2458 ddata->child_needs_resume = false;
2459
2460 error = sysc_runtime_resume(ddata->dev);
2461 if (error)
2462 dev_err(ddata->dev,
2463 "%s runtime resume error: %i\n",
2464 __func__, error);
2465
2466 error = pm_generic_runtime_resume(dev);
2467 if (error)
2468 dev_err(ddata->dev,
2469 "%s generic runtime resume: %i\n",
2470 __func__, error);
2471 }
2472
2473 return pm_generic_resume_noirq(dev);
2474}
2475#endif
2476
Tony Lindgrenb7182b42019-03-21 11:00:21 -07002477static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002478 .ops = {
2479 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
2480 sysc_child_runtime_resume,
2481 NULL)
2482 USE_PLATFORM_PM_SLEEP_OPS
2483 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
2484 sysc_child_resume_noirq)
2485 }
2486};
2487
Tony Lindgren9d8813612021-09-21 12:42:25 +03002488/* Caller needs to take list_lock if ever used outside of cpu_pm */
2489static void sysc_reinit_modules(struct sysc_soc_info *soc)
2490{
2491 struct sysc_module *module;
2492 struct list_head *pos;
2493 struct sysc *ddata;
2494 int error = 0;
2495
2496 list_for_each(pos, &sysc_soc->restored_modules) {
2497 module = list_entry(pos, struct sysc_module, node);
2498 ddata = module->ddata;
2499 error = sysc_reinit_module(ddata, ddata->enabled);
2500 }
2501}
2502
2503/**
2504 * sysc_context_notifier - optionally reset and restore module after idle
2505 * @nb: notifier block
2506 * @cmd: unused
2507 * @v: unused
2508 *
2509 * Some interconnect target modules need to be restored, or reset and restored
2510 * on CPU_PM CPU_PM_CLUSTER_EXIT notifier. This is needed at least for am335x
2511 * OTG and GPMC target modules even if the modules are unused.
2512 */
2513static int sysc_context_notifier(struct notifier_block *nb, unsigned long cmd,
2514 void *v)
2515{
2516 struct sysc_soc_info *soc;
2517
2518 soc = container_of(nb, struct sysc_soc_info, nb);
2519
2520 switch (cmd) {
2521 case CPU_CLUSTER_PM_ENTER:
2522 break;
2523 case CPU_CLUSTER_PM_ENTER_FAILED: /* No need to restore context */
2524 break;
2525 case CPU_CLUSTER_PM_EXIT:
2526 sysc_reinit_modules(soc);
2527 break;
2528 }
2529
2530 return NOTIFY_OK;
2531}
2532
2533/**
2534 * sysc_add_restored - optionally add reset and restore quirk hanlling
2535 * @ddata: device data
2536 */
2537static void sysc_add_restored(struct sysc *ddata)
2538{
2539 struct sysc_module *restored_module;
2540
2541 restored_module = kzalloc(sizeof(*restored_module), GFP_KERNEL);
2542 if (!restored_module)
2543 return;
2544
2545 restored_module->ddata = ddata;
2546
2547 mutex_lock(&sysc_soc->list_lock);
2548
2549 list_add(&restored_module->node, &sysc_soc->restored_modules);
2550
2551 if (sysc_soc->nb.notifier_call)
2552 goto out_unlock;
2553
2554 sysc_soc->nb.notifier_call = sysc_context_notifier;
2555 cpu_pm_register_notifier(&sysc_soc->nb);
2556
2557out_unlock:
2558 mutex_unlock(&sysc_soc->list_lock);
2559}
2560
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002561/**
2562 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
2563 * @ddata: device driver data
2564 * @child: child device driver
2565 *
2566 * Allow idle for child devices as done with _od_runtime_suspend().
2567 * Otherwise many child devices will not idle because of the permanent
2568 * parent usecount set in pm_runtime_irq_safe().
2569 *
2570 * Note that the long term solution is to just modify the child device
2571 * drivers to not set pm_runtime_irq_safe() and then this can be just
2572 * dropped.
2573 */
2574static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
2575{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002576 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
2577 dev_pm_domain_set(child, &sysc_child_pm_domain);
2578}
2579
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002580static int sysc_notifier_call(struct notifier_block *nb,
2581 unsigned long event, void *device)
2582{
2583 struct device *dev = device;
2584 struct sysc *ddata;
2585 int error;
2586
2587 ddata = sysc_child_to_parent(dev);
2588 if (!ddata)
2589 return NOTIFY_DONE;
2590
2591 switch (event) {
2592 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07002593 error = sysc_child_add_clocks(ddata, dev);
2594 if (error)
2595 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002596 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002597 break;
2598 default:
2599 break;
2600 }
2601
2602 return NOTIFY_DONE;
2603}
2604
2605static struct notifier_block sysc_nb = {
2606 .notifier_call = sysc_notifier_call,
2607};
2608
Tony Lindgren566a9b052017-12-15 09:41:19 -08002609/* Device tree configured quirks */
2610struct sysc_dts_quirk {
2611 const char *name;
2612 u32 mask;
2613};
2614
2615static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2616 { .name = "ti,no-idle-on-init",
2617 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2618 { .name = "ti,no-reset-on-init",
2619 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002620 { .name = "ti,no-idle",
2621 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002622};
2623
Tony Lindgren4014c082018-12-10 14:11:26 -08002624static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2625 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002626{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002627 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002628 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002629
2630 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002631 const char *name = sysc_dts_quirks[i].name;
2632
2633 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002634 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002635 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002636
2637 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002638 if (is_child) {
2639 dev_warn(ddata->dev,
2640 "dts flag should be at module level for %s\n",
2641 name);
2642 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002643 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002644}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002645
Tony Lindgren4014c082018-12-10 14:11:26 -08002646static int sysc_init_dts_quirks(struct sysc *ddata)
2647{
2648 struct device_node *np = ddata->dev->of_node;
2649 int error;
2650 u32 val;
2651
2652 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2653
2654 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002655 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2656 if (!error) {
2657 if (val > 255) {
2658 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2659 val);
2660 }
2661
2662 ddata->cfg.srst_udelay = (u8)val;
2663 }
2664
2665 return 0;
2666}
2667
Tony Lindgren0eecc632017-10-10 14:23:43 -07002668static void sysc_unprepare(struct sysc *ddata)
2669{
2670 int i;
2671
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002672 if (!ddata->clocks)
2673 return;
2674
Tony Lindgren0eecc632017-10-10 14:23:43 -07002675 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2676 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2677 clk_unprepare(ddata->clocks[i]);
2678 }
2679}
2680
Tony Lindgren70a65242017-12-15 09:41:09 -08002681/*
2682 * Common sysc register bits found on omap2, also known as type1
2683 */
2684static const struct sysc_regbits sysc_regbits_omap2 = {
2685 .dmadisable_shift = -ENODEV,
2686 .midle_shift = 12,
2687 .sidle_shift = 3,
2688 .clkact_shift = 8,
2689 .emufree_shift = 5,
2690 .enwkup_shift = 2,
2691 .srst_shift = 1,
2692 .autoidle_shift = 0,
2693};
2694
2695static const struct sysc_capabilities sysc_omap2 = {
2696 .type = TI_SYSC_OMAP2,
2697 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2698 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2699 SYSC_OMAP2_AUTOIDLE,
2700 .regbits = &sysc_regbits_omap2,
2701};
2702
2703/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2704static const struct sysc_capabilities sysc_omap2_timer = {
2705 .type = TI_SYSC_OMAP2_TIMER,
2706 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2707 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2708 SYSC_OMAP2_AUTOIDLE,
2709 .regbits = &sysc_regbits_omap2,
2710 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2711};
2712
2713/*
2714 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2715 * with different sidle position
2716 */
2717static const struct sysc_regbits sysc_regbits_omap3_sham = {
2718 .dmadisable_shift = -ENODEV,
2719 .midle_shift = -ENODEV,
2720 .sidle_shift = 4,
2721 .clkact_shift = -ENODEV,
2722 .enwkup_shift = -ENODEV,
2723 .srst_shift = 1,
2724 .autoidle_shift = 0,
2725 .emufree_shift = -ENODEV,
2726};
2727
2728static const struct sysc_capabilities sysc_omap3_sham = {
2729 .type = TI_SYSC_OMAP3_SHAM,
2730 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2731 .regbits = &sysc_regbits_omap3_sham,
2732};
2733
2734/*
2735 * AES register bits found on omap3 and later, a variant of
2736 * sysc_regbits_omap2 with different sidle position
2737 */
2738static const struct sysc_regbits sysc_regbits_omap3_aes = {
2739 .dmadisable_shift = -ENODEV,
2740 .midle_shift = -ENODEV,
2741 .sidle_shift = 6,
2742 .clkact_shift = -ENODEV,
2743 .enwkup_shift = -ENODEV,
2744 .srst_shift = 1,
2745 .autoidle_shift = 0,
2746 .emufree_shift = -ENODEV,
2747};
2748
2749static const struct sysc_capabilities sysc_omap3_aes = {
2750 .type = TI_SYSC_OMAP3_AES,
2751 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2752 .regbits = &sysc_regbits_omap3_aes,
2753};
2754
2755/*
2756 * Common sysc register bits found on omap4, also known as type2
2757 */
2758static const struct sysc_regbits sysc_regbits_omap4 = {
2759 .dmadisable_shift = 16,
2760 .midle_shift = 4,
2761 .sidle_shift = 2,
2762 .clkact_shift = -ENODEV,
2763 .enwkup_shift = -ENODEV,
2764 .emufree_shift = 1,
2765 .srst_shift = 0,
2766 .autoidle_shift = -ENODEV,
2767};
2768
2769static const struct sysc_capabilities sysc_omap4 = {
2770 .type = TI_SYSC_OMAP4,
2771 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2772 SYSC_OMAP4_SOFTRESET,
2773 .regbits = &sysc_regbits_omap4,
2774};
2775
2776static const struct sysc_capabilities sysc_omap4_timer = {
2777 .type = TI_SYSC_OMAP4_TIMER,
2778 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2779 SYSC_OMAP4_SOFTRESET,
2780 .regbits = &sysc_regbits_omap4,
2781};
2782
2783/*
2784 * Common sysc register bits found on omap4, also known as type3
2785 */
2786static const struct sysc_regbits sysc_regbits_omap4_simple = {
2787 .dmadisable_shift = -ENODEV,
2788 .midle_shift = 2,
2789 .sidle_shift = 0,
2790 .clkact_shift = -ENODEV,
2791 .enwkup_shift = -ENODEV,
2792 .srst_shift = -ENODEV,
2793 .emufree_shift = -ENODEV,
2794 .autoidle_shift = -ENODEV,
2795};
2796
2797static const struct sysc_capabilities sysc_omap4_simple = {
2798 .type = TI_SYSC_OMAP4_SIMPLE,
2799 .regbits = &sysc_regbits_omap4_simple,
2800};
2801
2802/*
2803 * SmartReflex sysc found on omap34xx
2804 */
2805static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2806 .dmadisable_shift = -ENODEV,
2807 .midle_shift = -ENODEV,
2808 .sidle_shift = -ENODEV,
2809 .clkact_shift = 20,
2810 .enwkup_shift = -ENODEV,
2811 .srst_shift = -ENODEV,
2812 .emufree_shift = -ENODEV,
2813 .autoidle_shift = -ENODEV,
2814};
2815
2816static const struct sysc_capabilities sysc_34xx_sr = {
2817 .type = TI_SYSC_OMAP34XX_SR,
2818 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2819 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002820 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2821 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002822};
2823
2824/*
2825 * SmartReflex sysc found on omap36xx and later
2826 */
2827static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2828 .dmadisable_shift = -ENODEV,
2829 .midle_shift = -ENODEV,
2830 .sidle_shift = 24,
2831 .clkact_shift = -ENODEV,
2832 .enwkup_shift = 26,
2833 .srst_shift = -ENODEV,
2834 .emufree_shift = -ENODEV,
2835 .autoidle_shift = -ENODEV,
2836};
2837
2838static const struct sysc_capabilities sysc_36xx_sr = {
2839 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002840 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002841 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002842 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002843};
2844
2845static const struct sysc_capabilities sysc_omap4_sr = {
2846 .type = TI_SYSC_OMAP4_SR,
2847 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002848 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002849};
2850
2851/*
2852 * McASP register bits found on omap4 and later
2853 */
2854static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2855 .dmadisable_shift = -ENODEV,
2856 .midle_shift = -ENODEV,
2857 .sidle_shift = 0,
2858 .clkact_shift = -ENODEV,
2859 .enwkup_shift = -ENODEV,
2860 .srst_shift = -ENODEV,
2861 .emufree_shift = -ENODEV,
2862 .autoidle_shift = -ENODEV,
2863};
2864
2865static const struct sysc_capabilities sysc_omap4_mcasp = {
2866 .type = TI_SYSC_OMAP4_MCASP,
2867 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002868 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2869};
2870
2871/*
2872 * McASP found on dra7 and later
2873 */
2874static const struct sysc_capabilities sysc_dra7_mcasp = {
2875 .type = TI_SYSC_OMAP4_SIMPLE,
2876 .regbits = &sysc_regbits_omap4_simple,
2877 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002878};
2879
2880/*
2881 * FS USB host found on omap4 and later
2882 */
2883static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2884 .dmadisable_shift = -ENODEV,
2885 .midle_shift = -ENODEV,
2886 .sidle_shift = 24,
2887 .clkact_shift = -ENODEV,
2888 .enwkup_shift = 26,
2889 .srst_shift = -ENODEV,
2890 .emufree_shift = -ENODEV,
2891 .autoidle_shift = -ENODEV,
2892};
2893
2894static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2895 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2896 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2897 .regbits = &sysc_regbits_omap4_usb_host_fs,
2898};
2899
Faiz Abbas7f35e632018-07-09 22:18:38 +05302900static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2901 .dmadisable_shift = -ENODEV,
2902 .midle_shift = -ENODEV,
2903 .sidle_shift = -ENODEV,
2904 .clkact_shift = -ENODEV,
2905 .enwkup_shift = 4,
2906 .srst_shift = 0,
2907 .emufree_shift = -ENODEV,
2908 .autoidle_shift = -ENODEV,
2909};
2910
2911static const struct sysc_capabilities sysc_dra7_mcan = {
2912 .type = TI_SYSC_DRA7_MCAN,
2913 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2914 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002915 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302916};
2917
Suman Annab2745d92020-02-27 16:28:34 -06002918/*
2919 * PRUSS found on some AM33xx, AM437x and AM57xx SoCs
2920 */
2921static const struct sysc_capabilities sysc_pruss = {
2922 .type = TI_SYSC_PRUSS,
2923 .sysc_mask = SYSC_PRUSS_STANDBY_INIT | SYSC_PRUSS_SUB_MWAIT,
2924 .regbits = &sysc_regbits_omap4_simple,
2925 .mod_quirks = SYSC_MODULE_QUIRK_PRUSS,
2926};
2927
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002928static int sysc_init_pdata(struct sysc *ddata)
2929{
2930 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002931 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002932
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002933 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002934 return 0;
2935
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002936 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2937 if (!mdata)
2938 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002939
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002940 if (ddata->legacy_mode) {
2941 mdata->name = ddata->legacy_mode;
2942 mdata->module_pa = ddata->module_pa;
2943 mdata->module_size = ddata->module_size;
2944 mdata->offsets = ddata->offsets;
2945 mdata->nr_offsets = SYSC_MAX_REGS;
2946 mdata->cap = ddata->cap;
2947 mdata->cfg = &ddata->cfg;
2948 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002949
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002950 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002951
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002952 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002953}
2954
Tony Lindgren70a65242017-12-15 09:41:09 -08002955static int sysc_init_match(struct sysc *ddata)
2956{
2957 const struct sysc_capabilities *cap;
2958
2959 cap = of_device_get_match_data(ddata->dev);
2960 if (!cap)
2961 return -EINVAL;
2962
2963 ddata->cap = cap;
2964 if (ddata->cap)
2965 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2966
2967 return 0;
2968}
2969
Tony Lindgren76f0f772018-02-23 08:28:45 -08002970static void ti_sysc_idle(struct work_struct *work)
2971{
2972 struct sysc *ddata;
2973
2974 ddata = container_of(work, struct sysc, idle_work.work);
2975
Tony Lindgrend0989132019-09-05 07:37:22 -07002976 /*
2977 * One time decrement of clock usage counts if left on from init.
2978 * Note that we disable opt clocks unconditionally in this case
2979 * as they are enabled unconditionally during init without
2980 * considering sysc_opt_clks_needed() at that point.
2981 */
2982 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2983 SYSC_QUIRK_NO_IDLE_ON_INIT)) {
Tony Lindgrend0989132019-09-05 07:37:22 -07002984 sysc_disable_main_clocks(ddata);
2985 sysc_disable_opt_clocks(ddata);
2986 sysc_clkdm_allow_idle(ddata);
2987 }
2988
2989 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
2990 if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE)
2991 return;
2992
2993 /*
2994 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
2995 * and SYSC_QUIRK_NO_RESET_ON_INIT
2996 */
Tony Lindgren76f0f772018-02-23 08:28:45 -08002997 if (pm_runtime_active(ddata->dev))
2998 pm_runtime_put_sync(ddata->dev);
2999}
3000
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003001/*
3002 * SoC model and features detection. Only needed for SoCs that need
3003 * special handling for quirks, no need to list others.
3004 */
3005static const struct soc_device_attribute sysc_soc_match[] = {
3006 SOC_FLAG("OMAP242*", SOC_2420),
3007 SOC_FLAG("OMAP243*", SOC_2430),
3008 SOC_FLAG("OMAP3[45]*", SOC_3430),
3009 SOC_FLAG("OMAP3[67]*", SOC_3630),
3010 SOC_FLAG("OMAP443*", SOC_4430),
3011 SOC_FLAG("OMAP446*", SOC_4460),
3012 SOC_FLAG("OMAP447*", SOC_4470),
3013 SOC_FLAG("OMAP54*", SOC_5430),
3014 SOC_FLAG("AM433", SOC_AM3),
3015 SOC_FLAG("AM43*", SOC_AM4),
3016 SOC_FLAG("DRA7*", SOC_DRA7),
3017
3018 { /* sentinel */ },
3019};
3020
3021/*
3022 * List of SoCs variants with disabled features. By default we assume all
3023 * devices in the device tree are available so no need to list those SoCs.
3024 */
3025static const struct soc_device_attribute sysc_soc_feat_match[] = {
3026 /* OMAP3430/3530 and AM3517 variants with some accelerators disabled */
3027 SOC_FLAG("AM3505", DIS_SGX),
3028 SOC_FLAG("OMAP3525", DIS_SGX),
3029 SOC_FLAG("OMAP3515", DIS_IVA | DIS_SGX),
3030 SOC_FLAG("OMAP3503", DIS_ISP | DIS_IVA | DIS_SGX),
3031
3032 /* OMAP3630/DM3730 variants with some accelerators disabled */
3033 SOC_FLAG("AM3703", DIS_IVA | DIS_SGX),
3034 SOC_FLAG("DM3725", DIS_SGX),
3035 SOC_FLAG("OMAP3611", DIS_ISP | DIS_IVA | DIS_SGX),
3036 SOC_FLAG("OMAP3615/AM3715", DIS_IVA),
3037 SOC_FLAG("OMAP3621", DIS_ISP),
3038
3039 { /* sentinel */ },
3040};
3041
3042static int sysc_add_disabled(unsigned long base)
3043{
3044 struct sysc_address *disabled_module;
3045
3046 disabled_module = kzalloc(sizeof(*disabled_module), GFP_KERNEL);
3047 if (!disabled_module)
3048 return -ENOMEM;
3049
3050 disabled_module->base = base;
3051
3052 mutex_lock(&sysc_soc->list_lock);
3053 list_add(&disabled_module->node, &sysc_soc->disabled_modules);
3054 mutex_unlock(&sysc_soc->list_lock);
3055
3056 return 0;
3057}
3058
3059/*
Tony Lindgren9d8813612021-09-21 12:42:25 +03003060 * One time init to detect the booted SoC, disable unavailable features
3061 * and initialize list for optional cpu_pm notifier.
3062 *
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003063 * Note that we initialize static data shared across all ti-sysc instances
3064 * so ddata is only used for SoC type. This can be called from module_init
3065 * once we no longer need to rely on platform data.
3066 */
Tony Lindgren9d8813612021-09-21 12:42:25 +03003067static int sysc_init_static_data(struct sysc *ddata)
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003068{
3069 const struct soc_device_attribute *match;
3070 struct ti_sysc_platform_data *pdata;
3071 unsigned long features = 0;
Tony Lindgren5f7259a2021-03-08 11:35:09 +02003072 struct device_node *np;
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003073
3074 if (sysc_soc)
3075 return 0;
3076
3077 sysc_soc = kzalloc(sizeof(*sysc_soc), GFP_KERNEL);
3078 if (!sysc_soc)
3079 return -ENOMEM;
3080
3081 mutex_init(&sysc_soc->list_lock);
3082 INIT_LIST_HEAD(&sysc_soc->disabled_modules);
Tony Lindgren9d8813612021-09-21 12:42:25 +03003083 INIT_LIST_HEAD(&sysc_soc->restored_modules);
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003084 sysc_soc->general_purpose = true;
3085
3086 pdata = dev_get_platdata(ddata->dev);
3087 if (pdata && pdata->soc_type_gp)
3088 sysc_soc->general_purpose = pdata->soc_type_gp();
3089
3090 match = soc_device_match(sysc_soc_match);
3091 if (match && match->data)
3092 sysc_soc->soc = (int)match->data;
3093
Tony Lindgren5f7259a2021-03-08 11:35:09 +02003094 /*
3095 * Check and warn about possible old incomplete dtb. We now want to see
3096 * simple-pm-bus instead of simple-bus in the dtb for genpd using SoCs.
3097 */
3098 switch (sysc_soc->soc) {
3099 case SOC_AM3:
3100 case SOC_AM4:
Tony Lindgren4adcf4c2021-03-12 10:23:48 +02003101 case SOC_4430 ... SOC_4470:
3102 case SOC_5430:
3103 case SOC_DRA7:
Tony Lindgren5f7259a2021-03-08 11:35:09 +02003104 np = of_find_node_by_path("/ocp");
3105 WARN_ONCE(np && of_device_is_compatible(np, "simple-bus"),
3106 "ti-sysc: Incomplete old dtb, please update\n");
3107 break;
3108 default:
3109 break;
3110 }
3111
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07003112 /* Ignore devices that are not available on HS and EMU SoCs */
3113 if (!sysc_soc->general_purpose) {
3114 switch (sysc_soc->soc) {
3115 case SOC_3430 ... SOC_3630:
3116 sysc_add_disabled(0x48304000); /* timer12 */
3117 break;
Kevin Hilmana6d90e92021-07-20 11:27:16 -07003118 case SOC_AM3:
3119 sysc_add_disabled(0x48310000); /* rng */
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07003120 default:
3121 break;
Yang Li52fbb5a2021-02-02 15:00:05 +08003122 }
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07003123 }
3124
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003125 match = soc_device_match(sysc_soc_feat_match);
3126 if (!match)
3127 return 0;
3128
3129 if (match->data)
3130 features = (unsigned long)match->data;
3131
3132 /*
3133 * Add disabled devices to the list based on the module base.
3134 * Note that this must be done before we attempt to access the
3135 * device and have module revision checks working.
3136 */
3137 if (features & DIS_ISP)
3138 sysc_add_disabled(0x480bd400);
3139 if (features & DIS_IVA)
3140 sysc_add_disabled(0x5d000000);
3141 if (features & DIS_SGX)
3142 sysc_add_disabled(0x50000000);
3143
3144 return 0;
3145}
3146
Tony Lindgren9d8813612021-09-21 12:42:25 +03003147static void sysc_cleanup_static_data(void)
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003148{
Tony Lindgren9d8813612021-09-21 12:42:25 +03003149 struct sysc_module *restored_module;
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003150 struct sysc_address *disabled_module;
3151 struct list_head *pos, *tmp;
3152
3153 if (!sysc_soc)
3154 return;
3155
Tony Lindgren9d8813612021-09-21 12:42:25 +03003156 if (sysc_soc->nb.notifier_call)
3157 cpu_pm_unregister_notifier(&sysc_soc->nb);
3158
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003159 mutex_lock(&sysc_soc->list_lock);
Tony Lindgren9d8813612021-09-21 12:42:25 +03003160 list_for_each_safe(pos, tmp, &sysc_soc->restored_modules) {
3161 restored_module = list_entry(pos, struct sysc_module, node);
3162 list_del(pos);
3163 kfree(restored_module);
3164 }
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003165 list_for_each_safe(pos, tmp, &sysc_soc->disabled_modules) {
3166 disabled_module = list_entry(pos, struct sysc_address, node);
3167 list_del(pos);
3168 kfree(disabled_module);
3169 }
3170 mutex_unlock(&sysc_soc->list_lock);
3171}
3172
3173static int sysc_check_disabled_devices(struct sysc *ddata)
3174{
3175 struct sysc_address *disabled_module;
3176 struct list_head *pos;
3177 int error = 0;
3178
3179 mutex_lock(&sysc_soc->list_lock);
3180 list_for_each(pos, &sysc_soc->disabled_modules) {
3181 disabled_module = list_entry(pos, struct sysc_address, node);
3182 if (ddata->module_pa == disabled_module->base) {
3183 dev_dbg(ddata->dev, "module disabled for this SoC\n");
3184 error = -ENODEV;
3185 break;
3186 }
3187 }
3188 mutex_unlock(&sysc_soc->list_lock);
3189
3190 return error;
3191}
3192
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003193/*
3194 * Ignore timers tagged with no-reset and no-idle. These are likely in use,
3195 * for example by drivers/clocksource/timer-ti-dm-systimer.c. If more checks
3196 * are needed, we could also look at the timer register configuration.
3197 */
3198static int sysc_check_active_timer(struct sysc *ddata)
3199{
3200 if (ddata->cap->type != TI_SYSC_OMAP2_TIMER &&
3201 ddata->cap->type != TI_SYSC_OMAP4_TIMER)
3202 return 0;
3203
3204 if ((ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) &&
3205 (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE))
Grygorii Strashko65fb7362020-11-18 16:19:00 +02003206 return -ENXIO;
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003207
3208 return 0;
3209}
3210
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07003211static const struct of_device_id sysc_match_table[] = {
3212 { .compatible = "simple-bus", },
3213 { /* sentinel */ },
3214};
3215
Tony Lindgren0eecc632017-10-10 14:23:43 -07003216static int sysc_probe(struct platform_device *pdev)
3217{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003218 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003219 struct sysc *ddata;
3220 int error;
3221
3222 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
3223 if (!ddata)
3224 return -ENOMEM;
3225
Tony Lindgren29281352020-11-16 12:57:13 +02003226 ddata->offsets[SYSC_REVISION] = -ENODEV;
3227 ddata->offsets[SYSC_SYSCONFIG] = -ENODEV;
3228 ddata->offsets[SYSC_SYSSTATUS] = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003229 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003230 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003231
Tony Lindgren9d8813612021-09-21 12:42:25 +03003232 error = sysc_init_static_data(ddata);
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003233 if (error)
3234 return error;
3235
Tony Lindgren70a65242017-12-15 09:41:09 -08003236 error = sysc_init_match(ddata);
3237 if (error)
3238 return error;
3239
Tony Lindgren566a9b052017-12-15 09:41:19 -08003240 error = sysc_init_dts_quirks(ddata);
3241 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003242 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003243
Tony Lindgren0eecc632017-10-10 14:23:43 -07003244 error = sysc_map_and_check_registers(ddata);
3245 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003246 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003247
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003248 error = sysc_init_sysc_mask(ddata);
3249 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003250 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003251
3252 error = sysc_init_idlemodes(ddata);
3253 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003254 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003255
3256 error = sysc_init_syss_mask(ddata);
3257 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003258 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003259
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003260 error = sysc_init_pdata(ddata);
3261 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003262 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003263
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003264 sysc_init_early_quirks(ddata);
3265
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003266 error = sysc_check_disabled_devices(ddata);
3267 if (error)
3268 return error;
3269
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003270 error = sysc_check_active_timer(ddata);
Tony Lindgren06a089e2021-08-11 08:34:46 +03003271 if (error == -ENXIO)
Tony Lindgren3ff340e2021-06-11 08:42:50 +03003272 ddata->reserved = true;
Tony Lindgren06a089e2021-08-11 08:34:46 +03003273 else if (error)
3274 return error;
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003275
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003276 error = sysc_get_clocks(ddata);
3277 if (error)
3278 return error;
3279
Tony Lindgren50622362018-04-16 10:20:27 -07003280 error = sysc_init_resets(ddata);
3281 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003282 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003283
3284 error = sysc_init_module(ddata);
3285 if (error)
3286 goto unprepare;
3287
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07003288 pm_runtime_enable(ddata->dev);
Zhang Qilongcea08162021-05-31 22:25:42 +08003289 error = pm_runtime_resume_and_get(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003290 if (error < 0) {
Tony Lindgren0eecc632017-10-10 14:23:43 -07003291 pm_runtime_disable(ddata->dev);
3292 goto unprepare;
3293 }
3294
Tero Kristocdc56c12019-10-07 15:29:31 +03003295 /* Balance use counts as PM runtime should have enabled these all */
Tero Kristocdc56c12019-10-07 15:29:31 +03003296 if (!(ddata->cfg.quirks &
3297 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))) {
3298 sysc_disable_main_clocks(ddata);
3299 sysc_disable_opt_clocks(ddata);
3300 sysc_clkdm_allow_idle(ddata);
3301 }
3302
Tony Lindgren4097c9a2020-11-16 12:57:13 +02003303 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
3304 reset_control_assert(ddata->rsts);
3305
Tony Lindgren0eecc632017-10-10 14:23:43 -07003306 sysc_show_registers(ddata);
3307
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003308 ddata->dev->type = &sysc_device_type;
Tony Lindgren3ff340e2021-06-11 08:42:50 +03003309
3310 if (!ddata->reserved) {
3311 error = of_platform_populate(ddata->dev->of_node,
3312 sysc_match_table,
3313 pdata ? pdata->auxdata : NULL,
3314 ddata->dev);
3315 if (error)
3316 goto err;
3317 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07003318
Tony Lindgren76f0f772018-02-23 08:28:45 -08003319 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
3320
3321 /* At least earlycon won't survive without deferred idle */
Tony Lindgrend0989132019-09-05 07:37:22 -07003322 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
3323 SYSC_QUIRK_NO_IDLE_ON_INIT |
Tony Lindgren76f0f772018-02-23 08:28:45 -08003324 SYSC_QUIRK_NO_RESET_ON_INIT)) {
3325 schedule_delayed_work(&ddata->idle_work, 3000);
3326 } else {
3327 pm_runtime_put(&pdev->dev);
3328 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07003329
Tony Lindgren9d8813612021-09-21 12:42:25 +03003330 if (ddata->cfg.quirks & SYSC_QUIRK_REINIT_ON_CTX_LOST)
3331 sysc_add_restored(ddata);
3332
Tony Lindgren0eecc632017-10-10 14:23:43 -07003333 return 0;
3334
3335err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07003336 pm_runtime_put_sync(&pdev->dev);
3337 pm_runtime_disable(&pdev->dev);
3338unprepare:
3339 sysc_unprepare(ddata);
3340
3341 return error;
3342}
3343
Tony Lindgren684be5a2017-10-13 10:48:40 -07003344static int sysc_remove(struct platform_device *pdev)
3345{
3346 struct sysc *ddata = platform_get_drvdata(pdev);
3347 int error;
3348
Tony Lindgren76f0f772018-02-23 08:28:45 -08003349 cancel_delayed_work_sync(&ddata->idle_work);
3350
Zhang Qilongcea08162021-05-31 22:25:42 +08003351 error = pm_runtime_resume_and_get(ddata->dev);
Tony Lindgren684be5a2017-10-13 10:48:40 -07003352 if (error < 0) {
Tony Lindgren684be5a2017-10-13 10:48:40 -07003353 pm_runtime_disable(ddata->dev);
3354 goto unprepare;
3355 }
3356
3357 of_platform_depopulate(&pdev->dev);
3358
Tony Lindgren684be5a2017-10-13 10:48:40 -07003359 pm_runtime_put_sync(&pdev->dev);
3360 pm_runtime_disable(&pdev->dev);
Tony Lindgrena7b5d7c2021-02-18 13:06:57 +02003361
3362 if (!reset_control_status(ddata->rsts))
3363 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07003364
3365unprepare:
3366 sysc_unprepare(ddata);
3367
3368 return 0;
3369}
3370
Tony Lindgren0eecc632017-10-10 14:23:43 -07003371static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08003372 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
3373 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
3374 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
3375 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
3376 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
3377 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
3378 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
3379 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
3380 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
3381 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
3382 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08003383 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08003384 { .compatible = "ti,sysc-usb-host-fs",
3385 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05303386 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Suman Annab2745d92020-02-27 16:28:34 -06003387 { .compatible = "ti,sysc-pruss", .data = &sysc_pruss, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07003388 { },
3389};
3390MODULE_DEVICE_TABLE(of, sysc_match);
3391
3392static struct platform_driver sysc_driver = {
3393 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07003394 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07003395 .driver = {
3396 .name = "ti-sysc",
3397 .of_match_table = sysc_match,
3398 .pm = &sysc_pm_ops,
3399 },
3400};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003401
3402static int __init sysc_init(void)
3403{
3404 bus_register_notifier(&platform_bus_type, &sysc_nb);
3405
3406 return platform_driver_register(&sysc_driver);
3407}
3408module_init(sysc_init);
3409
3410static void __exit sysc_exit(void)
3411{
3412 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
3413 platform_driver_unregister(&sysc_driver);
Tony Lindgren9d8813612021-09-21 12:42:25 +03003414 sysc_cleanup_static_data();
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003415}
3416module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003417
3418MODULE_DESCRIPTION("TI sysc interconnect target driver");
3419MODULE_LICENSE("GPL v2");