blob: 45e08528fdff7d8f1f251d064ca06d53d9026133 [file] [log] [blame]
Suman Anna54d66222019-08-13 04:13:32 -07001// SPDX-License-Identifier: GPL-2.0
Tony Lindgren0eecc632017-10-10 14:23:43 -07002/*
3 * ti-sysc.c - Texas Instruments sysc interconnect target driver
Tony Lindgren0eecc632017-10-10 14:23:43 -07004 */
5
6#include <linux/io.h>
7#include <linux/clk.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -08008#include <linux/clkdev.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -08009#include <linux/delay.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070010#include <linux/module.h>
11#include <linux/platform_device.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080012#include <linux/pm_domain.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070013#include <linux/pm_runtime.h>
Tony Lindgren50622362018-04-16 10:20:27 -070014#include <linux/reset.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070015#include <linux/of_address.h>
16#include <linux/of_platform.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080017#include <linux/slab.h>
Faiz Abbas596e7952018-07-09 22:18:39 +053018#include <linux/iopoll.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080019
Tony Lindgren70a65242017-12-15 09:41:09 -080020#include <linux/platform_data/ti-sysc.h>
21
22#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070023
Faiz Abbas596e7952018-07-09 22:18:39 +053024#define MAX_MODULE_SOFTRESET_WAIT 10000
25
Tony Lindgren0eecc632017-10-10 14:23:43 -070026static const char * const reg_names[] = { "rev", "sysc", "syss", };
27
28enum sysc_clocks {
29 SYSC_FCK,
30 SYSC_ICK,
Tony Lindgren09dfe582018-04-16 10:25:52 -070031 SYSC_OPTFCK0,
32 SYSC_OPTFCK1,
33 SYSC_OPTFCK2,
34 SYSC_OPTFCK3,
35 SYSC_OPTFCK4,
36 SYSC_OPTFCK5,
37 SYSC_OPTFCK6,
38 SYSC_OPTFCK7,
Tony Lindgren0eecc632017-10-10 14:23:43 -070039 SYSC_MAX_CLOCKS,
40};
41
Tony Lindgrena54275f2019-03-21 11:00:21 -070042static const char * const clock_names[SYSC_MAX_CLOCKS] = {
43 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
44 "opt5", "opt6", "opt7",
45};
Tony Lindgren0eecc632017-10-10 14:23:43 -070046
Tony Lindgrenc5a2de92017-12-15 09:41:23 -080047#define SYSC_IDLEMODE_MASK 3
48#define SYSC_CLOCKACTIVITY_MASK 3
49
Tony Lindgren0eecc632017-10-10 14:23:43 -070050/**
51 * struct sysc - TI sysc interconnect target module registers and capabilities
52 * @dev: struct device pointer
53 * @module_pa: physical address of the interconnect target module
54 * @module_size: size of the interconnect target module
55 * @module_va: virtual address of the interconnect target module
56 * @offsets: register offsets from module base
57 * @clocks: clocks used by the interconnect target module
Tony Lindgren09dfe582018-04-16 10:25:52 -070058 * @clock_roles: clock role names for the found clocks
59 * @nr_clocks: number of clocks used by the interconnect target module
Tony Lindgren0eecc632017-10-10 14:23:43 -070060 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -080061 * @cap: interconnect target module capabilities
62 * @cfg: interconnect target module configuration
Tony Lindgren566a9b052017-12-15 09:41:19 -080063 * @name: name if available
64 * @revision: interconnect target module revision
Tony Lindgren62020f22018-02-22 13:59:44 -080065 * @needs_resume: runtime resume needed on resume from suspend
Tony Lindgren4e23be42019-06-10 04:48:05 -070066 * @clk_enable_quirk: module specific clock enable quirk
67 * @clk_disable_quirk: module specific clock disable quirk
68 * @reset_done_quirk: module specific reset done quirk
Tony Lindgren0eecc632017-10-10 14:23:43 -070069 */
70struct sysc {
71 struct device *dev;
72 u64 module_pa;
73 u32 module_size;
74 void __iomem *module_va;
75 int offsets[SYSC_MAX_REGS];
Tony Lindgrena3e92e72019-03-21 11:00:21 -070076 struct ti_sysc_module_data *mdata;
Tony Lindgren09dfe582018-04-16 10:25:52 -070077 struct clk **clocks;
78 const char **clock_roles;
79 int nr_clocks;
Tony Lindgren50622362018-04-16 10:20:27 -070080 struct reset_control *rsts;
Tony Lindgren0eecc632017-10-10 14:23:43 -070081 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -080082 const struct sysc_capabilities *cap;
83 struct sysc_config cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -080084 struct ti_sysc_cookie cookie;
Tony Lindgren566a9b052017-12-15 09:41:19 -080085 const char *name;
86 u32 revision;
Tony Lindgren8383e252019-05-27 04:51:56 -070087 unsigned int enabled:1;
88 unsigned int needs_resume:1;
89 unsigned int child_needs_resume:1;
90 unsigned int disable_on_idle:1;
Tony Lindgren76f0f772018-02-23 08:28:45 -080091 struct delayed_work idle_work;
Tony Lindgren4e23be42019-06-10 04:48:05 -070092 void (*clk_enable_quirk)(struct sysc *sysc);
93 void (*clk_disable_quirk)(struct sysc *sysc);
94 void (*reset_done_quirk)(struct sysc *sysc);
Tony Lindgren0eecc632017-10-10 14:23:43 -070095};
96
Tony Lindgren4014c082018-12-10 14:11:26 -080097static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
98 bool is_child);
99
Tony Lindgrenb7182b42019-03-21 11:00:21 -0700100static void sysc_write(struct sysc *ddata, int offset, u32 value)
Faiz Abbas596e7952018-07-09 22:18:39 +0530101{
Tony Lindgren5aa91292019-05-27 04:51:53 -0700102 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
103 writew_relaxed(value & 0xffff, ddata->module_va + offset);
104
105 /* Only i2c revision has LO and HI register with stride of 4 */
106 if (ddata->offsets[SYSC_REVISION] >= 0 &&
107 offset == ddata->offsets[SYSC_REVISION]) {
108 u16 hi = value >> 16;
109
110 writew_relaxed(hi, ddata->module_va + offset + 4);
111 }
112
113 return;
114 }
115
Faiz Abbas596e7952018-07-09 22:18:39 +0530116 writel_relaxed(value, ddata->module_va + offset);
117}
118
Tony Lindgren566a9b052017-12-15 09:41:19 -0800119static u32 sysc_read(struct sysc *ddata, int offset)
120{
121 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
122 u32 val;
123
124 val = readw_relaxed(ddata->module_va + offset);
Tony Lindgren5aa91292019-05-27 04:51:53 -0700125
126 /* Only i2c revision has LO and HI register with stride of 4 */
127 if (ddata->offsets[SYSC_REVISION] >= 0 &&
128 offset == ddata->offsets[SYSC_REVISION]) {
129 u16 tmp = readw_relaxed(ddata->module_va + offset + 4);
130
131 val |= tmp << 16;
132 }
Tony Lindgren566a9b052017-12-15 09:41:19 -0800133
134 return val;
135 }
136
137 return readl_relaxed(ddata->module_va + offset);
138}
139
Tony Lindgren09dfe582018-04-16 10:25:52 -0700140static bool sysc_opt_clks_needed(struct sysc *ddata)
141{
142 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
143}
144
Tony Lindgren0eecc632017-10-10 14:23:43 -0700145static u32 sysc_read_revision(struct sysc *ddata)
146{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800147 int offset = ddata->offsets[SYSC_REVISION];
148
149 if (offset < 0)
150 return 0;
151
152 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700153}
154
Tony Lindgrene0db94f2019-05-27 04:51:53 -0700155static u32 sysc_read_sysconfig(struct sysc *ddata)
156{
157 int offset = ddata->offsets[SYSC_SYSCONFIG];
158
159 if (offset < 0)
160 return 0;
161
162 return sysc_read(ddata, offset);
163}
164
165static u32 sysc_read_sysstatus(struct sysc *ddata)
166{
167 int offset = ddata->offsets[SYSC_SYSSTATUS];
168
169 if (offset < 0)
170 return 0;
171
172 return sysc_read(ddata, offset);
173}
174
Tony Lindgrena54275f2019-03-21 11:00:21 -0700175static int sysc_add_named_clock_from_child(struct sysc *ddata,
176 const char *name,
177 const char *optfck_name)
178{
179 struct device_node *np = ddata->dev->of_node;
180 struct device_node *child;
181 struct clk_lookup *cl;
182 struct clk *clock;
183 const char *n;
184
185 if (name)
186 n = name;
187 else
188 n = optfck_name;
189
190 /* Does the clock alias already exist? */
191 clock = of_clk_get_by_name(np, n);
192 if (!IS_ERR(clock)) {
193 clk_put(clock);
194
195 return 0;
196 }
197
198 child = of_get_next_available_child(np, NULL);
199 if (!child)
200 return -ENODEV;
201
202 clock = devm_get_clk_from_child(ddata->dev, child, name);
203 if (IS_ERR(clock))
204 return PTR_ERR(clock);
205
206 /*
207 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
208 * limit for clk_get(). If cl ever needs to be freed, it should be done
209 * with clkdev_drop().
210 */
211 cl = kcalloc(1, sizeof(*cl), GFP_KERNEL);
212 if (!cl)
213 return -ENOMEM;
214
215 cl->con_id = n;
216 cl->dev_id = dev_name(ddata->dev);
217 cl->clk = clock;
218 clkdev_add(cl);
219
220 clk_put(clock);
221
222 return 0;
223}
224
225static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
226{
227 const char *optfck_name;
228 int error, index;
229
230 if (ddata->nr_clocks < SYSC_OPTFCK0)
231 index = SYSC_OPTFCK0;
232 else
233 index = ddata->nr_clocks;
234
235 if (name)
236 optfck_name = name;
237 else
238 optfck_name = clock_names[index];
239
240 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
241 if (error)
242 return error;
243
244 ddata->clock_roles[index] = optfck_name;
245 ddata->nr_clocks++;
246
247 return 0;
248}
249
Tony Lindgren09dfe582018-04-16 10:25:52 -0700250static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700251{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700252 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700253
Tony Lindgren09dfe582018-04-16 10:25:52 -0700254 if (!strncmp(clock_names[SYSC_FCK], name, 3))
255 index = SYSC_FCK;
256 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
257 index = SYSC_ICK;
258
259 if (index < 0) {
260 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700261 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700262 index = i;
263 break;
264 }
265 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700266 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700267
268 if (index < 0) {
269 dev_err(ddata->dev, "clock %s not added\n", name);
270 return index;
271 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700272
273 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
274 if (IS_ERR(ddata->clocks[index])) {
275 if (PTR_ERR(ddata->clocks[index]) == -ENOENT)
276 return 0;
277
278 dev_err(ddata->dev, "clock get error for %s: %li\n",
279 name, PTR_ERR(ddata->clocks[index]));
280
281 return PTR_ERR(ddata->clocks[index]);
282 }
283
284 error = clk_prepare(ddata->clocks[index]);
285 if (error) {
286 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
287 name, error);
288
289 return error;
290 }
291
292 return 0;
293}
294
295static int sysc_get_clocks(struct sysc *ddata)
296{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700297 struct device_node *np = ddata->dev->of_node;
298 struct property *prop;
299 const char *name;
300 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700301
Kees Cook20749052018-06-18 10:45:49 -0700302 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700303 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700304 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700305 GFP_KERNEL);
306 if (!ddata->clock_roles)
307 return -ENOMEM;
308
309 of_property_for_each_string(np, "clock-names", prop, name) {
310 if (!strncmp(clock_names[SYSC_FCK], name, 3))
311 nr_fck++;
312 if (!strncmp(clock_names[SYSC_ICK], name, 3))
313 nr_ick++;
314 ddata->clock_roles[ddata->nr_clocks] = name;
315 ddata->nr_clocks++;
316 }
317
318 if (ddata->nr_clocks < 1)
319 return 0;
320
Tony Lindgrena54275f2019-03-21 11:00:21 -0700321 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
322 error = sysc_init_ext_opt_clock(ddata, NULL);
323 if (error)
324 return error;
325 }
326
Tony Lindgren09dfe582018-04-16 10:25:52 -0700327 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
328 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
329
330 return -EINVAL;
331 }
332
333 if (nr_fck > 1 || nr_ick > 1) {
334 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
335
336 return -EINVAL;
337 }
338
Kees Cook20749052018-06-18 10:45:49 -0700339 ddata->clocks = devm_kcalloc(ddata->dev,
340 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700341 GFP_KERNEL);
342 if (!ddata->clocks)
343 return -ENOMEM;
344
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800345 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
346 const char *name = ddata->clock_roles[i];
347
348 if (!name)
349 continue;
350
351 error = sysc_get_one_clock(ddata, name);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700352 if (error && error != -ENOENT)
353 return error;
354 }
355
356 return 0;
357}
358
Tony Lindgrend8789702019-03-21 11:00:21 -0700359static int sysc_enable_main_clocks(struct sysc *ddata)
360{
361 struct clk *clock;
362 int i, error;
363
364 if (!ddata->clocks)
365 return 0;
366
367 for (i = 0; i < SYSC_OPTFCK0; i++) {
368 clock = ddata->clocks[i];
369
370 /* Main clocks may not have ick */
371 if (IS_ERR_OR_NULL(clock))
372 continue;
373
374 error = clk_enable(clock);
375 if (error)
376 goto err_disable;
377 }
378
379 return 0;
380
381err_disable:
382 for (i--; i >= 0; i--) {
383 clock = ddata->clocks[i];
384
385 /* Main clocks may not have ick */
386 if (IS_ERR_OR_NULL(clock))
387 continue;
388
389 clk_disable(clock);
390 }
391
392 return error;
393}
394
395static void sysc_disable_main_clocks(struct sysc *ddata)
396{
397 struct clk *clock;
398 int i;
399
400 if (!ddata->clocks)
401 return;
402
403 for (i = 0; i < SYSC_OPTFCK0; i++) {
404 clock = ddata->clocks[i];
405 if (IS_ERR_OR_NULL(clock))
406 continue;
407
408 clk_disable(clock);
409 }
410}
411
412static int sysc_enable_opt_clocks(struct sysc *ddata)
413{
414 struct clk *clock;
415 int i, error;
416
417 if (!ddata->clocks)
418 return 0;
419
420 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
421 clock = ddata->clocks[i];
422
423 /* Assume no holes for opt clocks */
424 if (IS_ERR_OR_NULL(clock))
425 return 0;
426
427 error = clk_enable(clock);
428 if (error)
429 goto err_disable;
430 }
431
432 return 0;
433
434err_disable:
435 for (i--; i >= 0; i--) {
436 clock = ddata->clocks[i];
437 if (IS_ERR_OR_NULL(clock))
438 continue;
439
440 clk_disable(clock);
441 }
442
443 return error;
444}
445
446static void sysc_disable_opt_clocks(struct sysc *ddata)
447{
448 struct clk *clock;
449 int i;
450
451 if (!ddata->clocks)
452 return;
453
454 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
455 clock = ddata->clocks[i];
456
457 /* Assume no holes for opt clocks */
458 if (IS_ERR_OR_NULL(clock))
459 return;
460
461 clk_disable(clock);
462 }
463}
464
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700465static void sysc_clkdm_deny_idle(struct sysc *ddata)
466{
467 struct ti_sysc_platform_data *pdata;
468
469 if (ddata->legacy_mode)
470 return;
471
472 pdata = dev_get_platdata(ddata->dev);
473 if (pdata && pdata->clkdm_deny_idle)
474 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
475}
476
477static void sysc_clkdm_allow_idle(struct sysc *ddata)
478{
479 struct ti_sysc_platform_data *pdata;
480
481 if (ddata->legacy_mode)
482 return;
483
484 pdata = dev_get_platdata(ddata->dev);
485 if (pdata && pdata->clkdm_allow_idle)
486 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
487}
488
Tony Lindgren0eecc632017-10-10 14:23:43 -0700489/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700490 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700491 * @ddata: device driver data
492 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700493 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700494 */
495static int sysc_init_resets(struct sysc *ddata)
496{
Tony Lindgren50622362018-04-16 10:20:27 -0700497 ddata->rsts =
Tony Lindgrenea5a2e42019-05-27 04:51:56 -0700498 devm_reset_control_get_optional(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700499 if (IS_ERR(ddata->rsts))
500 return PTR_ERR(ddata->rsts);
501
Tony Lindgren50622362018-04-16 10:20:27 -0700502 return 0;
503}
504
505/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700506 * sysc_parse_and_check_child_range - parses module IO region from ranges
507 * @ddata: device driver data
508 *
509 * In general we only need rev, syss, and sysc registers and not the whole
510 * module range. But we do want the offsets for these registers from the
511 * module base. This allows us to check them against the legacy hwmod
512 * platform data. Let's also check the ranges are configured properly.
513 */
514static int sysc_parse_and_check_child_range(struct sysc *ddata)
515{
516 struct device_node *np = ddata->dev->of_node;
517 const __be32 *ranges;
518 u32 nr_addr, nr_size;
519 int len, error;
520
521 ranges = of_get_property(np, "ranges", &len);
522 if (!ranges) {
523 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
524
525 return -ENOENT;
526 }
527
528 len /= sizeof(*ranges);
529
530 if (len < 3) {
531 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
532
533 return -EINVAL;
534 }
535
536 error = of_property_read_u32(np, "#address-cells", &nr_addr);
537 if (error)
538 return -ENOENT;
539
540 error = of_property_read_u32(np, "#size-cells", &nr_size);
541 if (error)
542 return -ENOENT;
543
544 if (nr_addr != 1 || nr_size != 1) {
545 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
546
547 return -EINVAL;
548 }
549
550 ranges++;
551 ddata->module_pa = of_translate_address(np, ranges++);
552 ddata->module_size = be32_to_cpup(ranges);
553
Tony Lindgren0eecc632017-10-10 14:23:43 -0700554 return 0;
555}
556
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800557static struct device_node *stdout_path;
558
559static void sysc_init_stdout_path(struct sysc *ddata)
560{
561 struct device_node *np = NULL;
562 const char *uart;
563
564 if (IS_ERR(stdout_path))
565 return;
566
567 if (stdout_path)
568 return;
569
570 np = of_find_node_by_path("/chosen");
571 if (!np)
572 goto err;
573
574 uart = of_get_property(np, "stdout-path", NULL);
575 if (!uart)
576 goto err;
577
578 np = of_find_node_by_path(uart);
579 if (!np)
580 goto err;
581
582 stdout_path = np;
583
584 return;
585
586err:
587 stdout_path = ERR_PTR(-ENODEV);
588}
589
590static void sysc_check_quirk_stdout(struct sysc *ddata,
591 struct device_node *np)
592{
593 sysc_init_stdout_path(ddata);
594 if (np != stdout_path)
595 return;
596
597 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
598 SYSC_QUIRK_NO_RESET_ON_INIT;
599}
600
Tony Lindgren0eecc632017-10-10 14:23:43 -0700601/**
602 * sysc_check_one_child - check child configuration
603 * @ddata: device driver data
604 * @np: child device node
605 *
606 * Let's avoid messy situations where we have new interconnect target
607 * node but children have "ti,hwmods". These belong to the interconnect
608 * target node and are managed by this driver.
609 */
610static int sysc_check_one_child(struct sysc *ddata,
611 struct device_node *np)
612{
613 const char *name;
614
615 name = of_get_property(np, "ti,hwmods", NULL);
616 if (name)
617 dev_warn(ddata->dev, "really a child ti,hwmods property?");
618
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800619 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800620 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800621
Tony Lindgren0eecc632017-10-10 14:23:43 -0700622 return 0;
623}
624
625static int sysc_check_children(struct sysc *ddata)
626{
627 struct device_node *child;
628 int error;
629
630 for_each_child_of_node(ddata->dev->of_node, child) {
631 error = sysc_check_one_child(ddata, child);
632 if (error)
633 return error;
634 }
635
636 return 0;
637}
638
Tony Lindgrena7199e22017-12-15 09:41:14 -0800639/*
640 * So far only I2C uses 16-bit read access with clockactivity with revision
641 * in two registers with stride of 4. We can detect this based on the rev
642 * register size to configure things far enough to be able to properly read
643 * the revision register.
644 */
645static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
646{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800647 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800648 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800649}
650
Tony Lindgren0eecc632017-10-10 14:23:43 -0700651/**
652 * sysc_parse_one - parses the interconnect target module registers
653 * @ddata: device driver data
654 * @reg: register to parse
655 */
656static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
657{
658 struct resource *res;
659 const char *name;
660
661 switch (reg) {
662 case SYSC_REVISION:
663 case SYSC_SYSCONFIG:
664 case SYSC_SYSSTATUS:
665 name = reg_names[reg];
666 break;
667 default:
668 return -EINVAL;
669 }
670
671 res = platform_get_resource_byname(to_platform_device(ddata->dev),
672 IORESOURCE_MEM, name);
673 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700674 ddata->offsets[reg] = -ENODEV;
675
676 return 0;
677 }
678
679 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800680 if (reg == SYSC_REVISION)
681 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700682
683 return 0;
684}
685
686static int sysc_parse_registers(struct sysc *ddata)
687{
688 int i, error;
689
690 for (i = 0; i < SYSC_MAX_REGS; i++) {
691 error = sysc_parse_one(ddata, i);
692 if (error)
693 return error;
694 }
695
696 return 0;
697}
698
699/**
700 * sysc_check_registers - check for misconfigured register overlaps
701 * @ddata: device driver data
702 */
703static int sysc_check_registers(struct sysc *ddata)
704{
705 int i, j, nr_regs = 0, nr_matches = 0;
706
707 for (i = 0; i < SYSC_MAX_REGS; i++) {
708 if (ddata->offsets[i] < 0)
709 continue;
710
711 if (ddata->offsets[i] > (ddata->module_size - 4)) {
712 dev_err(ddata->dev, "register outside module range");
713
714 return -EINVAL;
715 }
716
717 for (j = 0; j < SYSC_MAX_REGS; j++) {
718 if (ddata->offsets[j] < 0)
719 continue;
720
721 if (ddata->offsets[i] == ddata->offsets[j])
722 nr_matches++;
723 }
724 nr_regs++;
725 }
726
Tony Lindgren0eecc632017-10-10 14:23:43 -0700727 if (nr_matches > nr_regs) {
728 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
729 nr_regs, nr_matches);
730
731 return -EINVAL;
732 }
733
734 return 0;
735}
736
737/**
738 * syc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700739 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700740 *
741 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700742 * within the interconnect target module range. For example, SGX has
743 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
744 * has them at offset 0x1200 in the CPSW_WR child. Usually the
745 * the interconnect target module registers are at the beginning of
746 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700747 */
748static int sysc_ioremap(struct sysc *ddata)
749{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700750 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700751
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700752 if (ddata->offsets[SYSC_REVISION] < 0 &&
753 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
754 ddata->offsets[SYSC_SYSSTATUS] < 0) {
755 size = ddata->module_size;
756 } else {
757 size = max3(ddata->offsets[SYSC_REVISION],
758 ddata->offsets[SYSC_SYSCONFIG],
759 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700760
Tony Lindgren4e23be42019-06-10 04:48:05 -0700761 if (size < SZ_1K)
762 size = SZ_1K;
763
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700764 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700765 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700766 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700767
Tony Lindgren0eecc632017-10-10 14:23:43 -0700768 ddata->module_va = devm_ioremap(ddata->dev,
769 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700770 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700771 if (!ddata->module_va)
772 return -EIO;
773
774 return 0;
775}
776
777/**
778 * sysc_map_and_check_registers - ioremap and check device registers
779 * @ddata: device driver data
780 */
781static int sysc_map_and_check_registers(struct sysc *ddata)
782{
783 int error;
784
785 error = sysc_parse_and_check_child_range(ddata);
786 if (error)
787 return error;
788
789 error = sysc_check_children(ddata);
790 if (error)
791 return error;
792
793 error = sysc_parse_registers(ddata);
794 if (error)
795 return error;
796
797 error = sysc_ioremap(ddata);
798 if (error)
799 return error;
800
801 error = sysc_check_registers(ddata);
802 if (error)
803 return error;
804
805 return 0;
806}
807
808/**
809 * sysc_show_rev - read and show interconnect target module revision
810 * @bufp: buffer to print the information to
811 * @ddata: device driver data
812 */
813static int sysc_show_rev(char *bufp, struct sysc *ddata)
814{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800815 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700816
817 if (ddata->offsets[SYSC_REVISION] < 0)
818 return sprintf(bufp, ":NA");
819
Tony Lindgren566a9b052017-12-15 09:41:19 -0800820 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700821
822 return len;
823}
824
825static int sysc_show_reg(struct sysc *ddata,
826 char *bufp, enum sysc_registers reg)
827{
828 if (ddata->offsets[reg] < 0)
829 return sprintf(bufp, ":NA");
830
831 return sprintf(bufp, ":%x", ddata->offsets[reg]);
832}
833
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800834static int sysc_show_name(char *bufp, struct sysc *ddata)
835{
836 if (!ddata->name)
837 return 0;
838
839 return sprintf(bufp, ":%s", ddata->name);
840}
841
Tony Lindgren0eecc632017-10-10 14:23:43 -0700842/**
843 * sysc_show_registers - show information about interconnect target module
844 * @ddata: device driver data
845 */
846static void sysc_show_registers(struct sysc *ddata)
847{
848 char buf[128];
849 char *bufp = buf;
850 int i;
851
852 for (i = 0; i < SYSC_MAX_REGS; i++)
853 bufp += sysc_show_reg(ddata, bufp, i);
854
855 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800856 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700857
858 dev_dbg(ddata->dev, "%llx:%x%s\n",
859 ddata->module_pa, ddata->module_size,
860 buf);
861}
862
Roger Quadrosd59b6052019-04-08 12:52:39 +0300863#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700864#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +0300865
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700866/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300867static int sysc_enable_module(struct device *dev)
868{
869 struct sysc *ddata;
870 const struct sysc_regbits *regbits;
871 u32 reg, idlemodes, best_mode;
872
873 ddata = dev_get_drvdata(dev);
874 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
875 return 0;
876
Roger Quadrosd59b6052019-04-08 12:52:39 +0300877 regbits = ddata->cap->regbits;
878 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
879
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700880 /* Set CLOCKACTIVITY, we only use it for ick */
881 if (regbits->clkact_shift >= 0 &&
882 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT ||
883 ddata->cfg.sysc_val & BIT(regbits->clkact_shift)))
884 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
885
Roger Quadrosd59b6052019-04-08 12:52:39 +0300886 /* Set SIDLE mode */
887 idlemodes = ddata->cfg.sidlemodes;
888 if (!idlemodes || regbits->sidle_shift < 0)
889 goto set_midle;
890
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700891 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
892 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
893 best_mode = SYSC_IDLE_NO;
894 } else {
895 best_mode = fls(ddata->cfg.sidlemodes) - 1;
896 if (best_mode > SYSC_IDLE_MASK) {
897 dev_err(dev, "%s: invalid sidlemode\n", __func__);
898 return -EINVAL;
899 }
Tony Lindgren6e09f492019-05-27 04:51:55 -0700900
901 /* Set WAKEUP */
902 if (regbits->enwkup_shift >= 0 &&
903 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
904 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +0300905 }
906
907 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
908 reg |= best_mode << regbits->sidle_shift;
909 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
910
911set_midle:
912 /* Set MIDLE mode */
913 idlemodes = ddata->cfg.midlemodes;
914 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -0700915 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +0300916
917 best_mode = fls(ddata->cfg.midlemodes) - 1;
918 if (best_mode > SYSC_IDLE_MASK) {
919 dev_err(dev, "%s: invalid midlemode\n", __func__);
920 return -EINVAL;
921 }
922
923 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
924 reg |= best_mode << regbits->midle_shift;
925 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
926
Tony Lindgreneec26552019-05-27 04:51:54 -0700927set_autoidle:
928 /* Autoidle bit must enabled separately if available */
929 if (regbits->autoidle_shift >= 0 &&
930 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
931 reg |= 1 << regbits->autoidle_shift;
932 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
933 }
934
Roger Quadrosd59b6052019-04-08 12:52:39 +0300935 return 0;
936}
937
938static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
939{
940 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
941 *best_mode = SYSC_IDLE_SMART_WKUP;
942 else if (idlemodes & BIT(SYSC_IDLE_SMART))
943 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -0700944 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +0300945 *best_mode = SYSC_IDLE_FORCE;
946 else
947 return -EINVAL;
948
949 return 0;
950}
951
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700952/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300953static int sysc_disable_module(struct device *dev)
954{
955 struct sysc *ddata;
956 const struct sysc_regbits *regbits;
957 u32 reg, idlemodes, best_mode;
958 int ret;
959
960 ddata = dev_get_drvdata(dev);
961 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
962 return 0;
963
Roger Quadrosd59b6052019-04-08 12:52:39 +0300964 regbits = ddata->cap->regbits;
965 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
966
967 /* Set MIDLE mode */
968 idlemodes = ddata->cfg.midlemodes;
969 if (!idlemodes || regbits->midle_shift < 0)
970 goto set_sidle;
971
972 ret = sysc_best_idle_mode(idlemodes, &best_mode);
973 if (ret) {
974 dev_err(dev, "%s: invalid midlemode\n", __func__);
975 return ret;
976 }
977
978 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
979 reg |= best_mode << regbits->midle_shift;
980 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
981
982set_sidle:
983 /* Set SIDLE mode */
984 idlemodes = ddata->cfg.sidlemodes;
985 if (!idlemodes || regbits->sidle_shift < 0)
986 return 0;
987
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700988 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
989 best_mode = SYSC_IDLE_FORCE;
990 } else {
991 ret = sysc_best_idle_mode(idlemodes, &best_mode);
992 if (ret) {
993 dev_err(dev, "%s: invalid sidlemode\n", __func__);
994 return ret;
995 }
Roger Quadrosd59b6052019-04-08 12:52:39 +0300996 }
997
998 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
999 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -07001000 if (regbits->autoidle_shift >= 0 &&
1001 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1002 reg |= 1 << regbits->autoidle_shift;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001003 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
1004
1005 return 0;
1006}
1007
Tony Lindgrenff437282019-03-21 11:00:21 -07001008static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1009 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001010{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001011 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001012 int error;
1013
1014 pdata = dev_get_platdata(ddata->dev);
1015 if (!pdata)
1016 return 0;
1017
1018 if (!pdata->idle_module)
1019 return -ENODEV;
1020
1021 error = pdata->idle_module(dev, &ddata->cookie);
1022 if (error)
1023 dev_err(dev, "%s: could not idle: %i\n",
1024 __func__, error);
1025
Tony Lindgren8383e252019-05-27 04:51:56 -07001026 if (ddata->disable_on_idle)
1027 reset_control_assert(ddata->rsts);
1028
Tony Lindgrenff437282019-03-21 11:00:21 -07001029 return 0;
1030}
1031
1032static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1033 struct sysc *ddata)
1034{
1035 struct ti_sysc_platform_data *pdata;
1036 int error;
1037
Tony Lindgren8383e252019-05-27 04:51:56 -07001038 if (ddata->disable_on_idle)
1039 reset_control_deassert(ddata->rsts);
1040
Tony Lindgrenff437282019-03-21 11:00:21 -07001041 pdata = dev_get_platdata(ddata->dev);
1042 if (!pdata)
1043 return 0;
1044
1045 if (!pdata->enable_module)
1046 return -ENODEV;
1047
1048 error = pdata->enable_module(dev, &ddata->cookie);
1049 if (error)
1050 dev_err(dev, "%s: could not enable: %i\n",
1051 __func__, error);
1052
1053 return 0;
1054}
1055
1056static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1057{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001058 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001059 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001060
1061 ddata = dev_get_drvdata(dev);
1062
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001063 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001064 return 0;
1065
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001066 sysc_clkdm_deny_idle(ddata);
1067
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001068 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001069 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001070 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001071 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001072 } else {
1073 error = sysc_disable_module(dev);
1074 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001075 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001076 }
1077
Tony Lindgrend8789702019-03-21 11:00:21 -07001078 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001079
Tony Lindgrend8789702019-03-21 11:00:21 -07001080 if (sysc_opt_clks_needed(ddata))
1081 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001082
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001083 ddata->enabled = false;
1084
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001085err_allow_idle:
1086 sysc_clkdm_allow_idle(ddata);
1087
Tony Lindgren8383e252019-05-27 04:51:56 -07001088 if (ddata->disable_on_idle)
1089 reset_control_assert(ddata->rsts);
1090
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001091 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001092}
1093
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001094static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001095{
1096 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001097 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001098
1099 ddata = dev_get_drvdata(dev);
1100
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001101 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001102 return 0;
1103
Tony Lindgren8383e252019-05-27 04:51:56 -07001104 if (ddata->disable_on_idle)
1105 reset_control_deassert(ddata->rsts);
1106
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001107 sysc_clkdm_deny_idle(ddata);
1108
Tony Lindgrend8789702019-03-21 11:00:21 -07001109 if (sysc_opt_clks_needed(ddata)) {
1110 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001111 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001112 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001113 }
1114
Tony Lindgrend8789702019-03-21 11:00:21 -07001115 error = sysc_enable_main_clocks(ddata);
1116 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001117 goto err_opt_clocks;
1118
1119 if (ddata->legacy_mode) {
1120 error = sysc_runtime_resume_legacy(dev, ddata);
1121 if (error)
1122 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001123 } else {
1124 error = sysc_enable_module(dev);
1125 if (error)
1126 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001127 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001128
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001129 ddata->enabled = true;
1130
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001131 sysc_clkdm_allow_idle(ddata);
1132
Tony Lindgrend8789702019-03-21 11:00:21 -07001133 return 0;
1134
1135err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001136 sysc_disable_main_clocks(ddata);
1137err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001138 if (sysc_opt_clks_needed(ddata))
1139 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001140err_allow_idle:
1141 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001142
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001143 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001144}
1145
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001146static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001147{
1148 struct sysc *ddata;
1149
1150 ddata = dev_get_drvdata(dev);
1151
Tony Lindgren40d9f912018-09-24 12:16:54 -07001152 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001153 return 0;
1154
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001155 return pm_runtime_force_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001156}
1157
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001158static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001159{
1160 struct sysc *ddata;
1161
1162 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001163
Tony Lindgren40d9f912018-09-24 12:16:54 -07001164 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001165 return 0;
1166
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001167 return pm_runtime_force_resume(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001168}
1169
Tony Lindgren0eecc632017-10-10 14:23:43 -07001170static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001171 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001172 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1173 sysc_runtime_resume,
1174 NULL)
1175};
1176
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001177/* Module revision register based quirks */
1178struct sysc_revision_quirk {
1179 const char *name;
1180 u32 base;
1181 int rev_offset;
1182 int sysc_offset;
1183 int syss_offset;
1184 u32 revision;
1185 u32 revision_mask;
1186 u32 quirks;
1187};
1188
1189#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1190 optrev_val, optrevmask, optquirkmask) \
1191 { \
1192 .name = (optname), \
1193 .base = (optbase), \
1194 .rev_offset = (optrev), \
1195 .sysc_offset = (optsysc), \
1196 .syss_offset = (optsyss), \
1197 .revision = (optrev_val), \
1198 .revision_mask = (optrevmask), \
1199 .quirks = (optquirkmask), \
1200 }
1201
1202static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1203 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001204 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -07001205 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001206 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
1207 SYSC_QUIRK_LEGACY_IDLE),
1208 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff,
1209 SYSC_QUIRK_LEGACY_IDLE),
1210 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1211 SYSC_QUIRK_LEGACY_IDLE),
1212 SYSC_QUIRK("smartreflex", 0, -1, 0x24, -1, 0x00000000, 0xffffffff,
1213 SYSC_QUIRK_LEGACY_IDLE),
1214 SYSC_QUIRK("smartreflex", 0, -1, 0x38, -1, 0x00000000, 0xffffffff,
1215 SYSC_QUIRK_LEGACY_IDLE),
1216 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001217 0),
Tony Lindgren8cde5d52018-04-16 10:25:15 -07001218 /* Some timers on omap4 and later */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001219 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x50002100, 0xffffffff,
Tony Lindgren072167d2019-01-29 07:53:47 -08001220 0),
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001221 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x4fff1301, 0xffff00ff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001222 0),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001223 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1224 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001225 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001226 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001227 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001228 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001229 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001230 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001231 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001232
Tony Lindgrena54275f2019-03-21 11:00:21 -07001233 /* Quirks that need to be set based on the module address */
1234 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -1, 0x50000800, 0xffffffff,
1235 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1236 SYSC_QUIRK_SWSUP_SIDLE),
1237
Tony Lindgren4e23be42019-06-10 04:48:05 -07001238 /* Quirks that need to be set based on detected module */
1239 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
1240 SYSC_MODULE_QUIRK_HDQ1W),
1241 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
1242 SYSC_MODULE_QUIRK_HDQ1W),
1243 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
1244 SYSC_MODULE_QUIRK_I2C),
1245 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
1246 SYSC_MODULE_QUIRK_I2C),
1247 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
1248 SYSC_MODULE_QUIRK_I2C),
1249 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
1250 SYSC_MODULE_QUIRK_I2C),
1251 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1252 SYSC_MODULE_QUIRK_WDT),
1253
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001254#ifdef DEBUG
Tony Lindgren1ba30692018-09-24 12:17:05 -07001255 SYSC_QUIRK("adc", 0, 0, 0x10, -1, 0x47300001, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001256 SYSC_QUIRK("atl", 0, 0, -1, -1, 0x0a070100, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001257 SYSC_QUIRK("aess", 0, 0, 0x10, -1, 0x40000000, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001258 SYSC_QUIRK("cm", 0, 0, -1, -1, 0x40000301, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001259 SYSC_QUIRK("control", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001260 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001261 0xffff00f0, 0),
Tony Lindgren89bbc6f2019-07-22 03:44:42 -07001262 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0xa3170504, 0xffffffff, 0),
1263 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren13aad512019-03-21 11:00:21 -07001264 SYSC_QUIRK("dmic", 0, 0, 0x10, -1, 0x50010000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001265 SYSC_QUIRK("dwc3", 0, 0, 0x10, -1, 0x500a0200, 0xffffffff, 0),
1266 SYSC_QUIRK("epwmss", 0, 0, 0x4, -1, 0x47400001, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001267 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -1, 0, 0, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001268 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
1269 SYSC_QUIRK("iss", 0, 0, 0x10, -1, 0x40000101, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001270 SYSC_QUIRK("lcdc", 0, 0, 0x54, -1, 0x4f201000, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001271 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44306302, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001272 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44307b02, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001273 SYSC_QUIRK("mcbsp", 0, -1, 0x8c, -1, 0, 0, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001274 SYSC_QUIRK("mcspi", 0, 0, 0x10, -1, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001275 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001276 SYSC_QUIRK("mailbox", 0, 0, 0x10, -1, 0x00000400, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001277 SYSC_QUIRK("m3", 0, 0, -1, -1, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001278 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001279 SYSC_QUIRK("ocp2scp", 0, 0, -1, -1, 0x50060007, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001280 SYSC_QUIRK("padconf", 0, 0, 0x10, -1, 0x4fff0800, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001281 SYSC_QUIRK("padconf", 0, 0, -1, -1, 0x40001100, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001282 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000100, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001283 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x00004102, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001284 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000400, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001285 SYSC_QUIRK("scm", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001286 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4e8b0100, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001287 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4f000100, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001288 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001289 SYSC_QUIRK("scrm", 0, 0, -1, -1, 0x00000010, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001290 SYSC_QUIRK("sdio", 0, 0, 0x10, -1, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001291 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001292 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001293 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40000902, 0xffffffff, 0),
1294 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40002903, 0xffffffff, 0),
1295 SYSC_QUIRK("spinlock", 0, 0, 0x10, -1, 0x50020000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001296 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -1, 0x00000020, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001297 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -1, 0x4eb01908, 0xffff00f0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001298 SYSC_QUIRK("timer32k", 0, 0, 0x4, -1, 0x00000060, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001299 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001300 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001301 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001302 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -1, 0x50700101, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001303 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1304 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001305 SYSC_QUIRK("vfpe", 0, 0, 0x104, -1, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001306#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001307};
1308
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001309/*
1310 * Early quirks based on module base and register offsets only that are
1311 * needed before the module revision can be read
1312 */
1313static void sysc_init_early_quirks(struct sysc *ddata)
1314{
1315 const struct sysc_revision_quirk *q;
1316 int i;
1317
1318 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1319 q = &sysc_revision_quirks[i];
1320
1321 if (!q->base)
1322 continue;
1323
1324 if (q->base != ddata->module_pa)
1325 continue;
1326
1327 if (q->rev_offset >= 0 &&
1328 q->rev_offset != ddata->offsets[SYSC_REVISION])
1329 continue;
1330
1331 if (q->sysc_offset >= 0 &&
1332 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1333 continue;
1334
1335 if (q->syss_offset >= 0 &&
1336 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1337 continue;
1338
1339 ddata->name = q->name;
1340 ddata->cfg.quirks |= q->quirks;
1341 }
1342}
1343
1344/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001345static void sysc_init_revision_quirks(struct sysc *ddata)
1346{
1347 const struct sysc_revision_quirk *q;
1348 int i;
1349
1350 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1351 q = &sysc_revision_quirks[i];
1352
1353 if (q->base && q->base != ddata->module_pa)
1354 continue;
1355
1356 if (q->rev_offset >= 0 &&
1357 q->rev_offset != ddata->offsets[SYSC_REVISION])
1358 continue;
1359
1360 if (q->sysc_offset >= 0 &&
1361 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1362 continue;
1363
1364 if (q->syss_offset >= 0 &&
1365 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1366 continue;
1367
1368 if (q->revision == ddata->revision ||
1369 (q->revision & q->revision_mask) ==
1370 (ddata->revision & q->revision_mask)) {
1371 ddata->name = q->name;
1372 ddata->cfg.quirks |= q->quirks;
1373 }
1374 }
1375}
1376
Tony Lindgren4e23be42019-06-10 04:48:05 -07001377/* 1-wire needs module's internal clocks enabled for reset */
1378static void sysc_clk_enable_quirk_hdq1w(struct sysc *ddata)
1379{
1380 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1381 u16 val;
1382
1383 val = sysc_read(ddata, offset);
1384 val |= BIT(5);
1385 sysc_write(ddata, offset, val);
1386}
1387
1388/* I2C needs extra enable bit toggling for reset */
1389static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1390{
1391 int offset;
1392 u16 val;
1393
1394 /* I2C_CON, omap2/3 is different from omap4 and later */
1395 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1396 offset = 0x24;
1397 else
1398 offset = 0xa4;
1399
1400 /* I2C_EN */
1401 val = sysc_read(ddata, offset);
1402 if (enable)
1403 val |= BIT(15);
1404 else
1405 val &= ~BIT(15);
1406 sysc_write(ddata, offset, val);
1407}
1408
1409static void sysc_clk_enable_quirk_i2c(struct sysc *ddata)
1410{
1411 sysc_clk_quirk_i2c(ddata, true);
1412}
1413
1414static void sysc_clk_disable_quirk_i2c(struct sysc *ddata)
1415{
1416 sysc_clk_quirk_i2c(ddata, false);
1417}
1418
1419/* Watchdog timer needs a disable sequence after reset */
1420static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1421{
1422 int wps, spr, error;
1423 u32 val;
1424
1425 wps = 0x34;
1426 spr = 0x48;
1427
1428 sysc_write(ddata, spr, 0xaaaa);
1429 error = readl_poll_timeout(ddata->module_va + wps, val,
1430 !(val & 0x10), 100,
1431 MAX_MODULE_SOFTRESET_WAIT);
1432 if (error)
1433 dev_warn(ddata->dev, "wdt disable spr failed\n");
1434
1435 sysc_write(ddata, wps, 0x5555);
1436 error = readl_poll_timeout(ddata->module_va + wps, val,
1437 !(val & 0x10), 100,
1438 MAX_MODULE_SOFTRESET_WAIT);
1439 if (error)
1440 dev_warn(ddata->dev, "wdt disable wps failed\n");
1441}
1442
1443static void sysc_init_module_quirks(struct sysc *ddata)
1444{
1445 if (ddata->legacy_mode || !ddata->name)
1446 return;
1447
1448 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
1449 ddata->clk_enable_quirk = sysc_clk_enable_quirk_hdq1w;
1450
1451 return;
1452 }
1453
1454 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
1455 ddata->clk_enable_quirk = sysc_clk_enable_quirk_i2c;
1456 ddata->clk_disable_quirk = sysc_clk_disable_quirk_i2c;
1457
1458 return;
1459 }
1460
1461 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT)
1462 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
1463}
1464
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001465static int sysc_clockdomain_init(struct sysc *ddata)
1466{
1467 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1468 struct clk *fck = NULL, *ick = NULL;
1469 int error;
1470
1471 if (!pdata || !pdata->init_clockdomain)
1472 return 0;
1473
1474 switch (ddata->nr_clocks) {
1475 case 2:
1476 ick = ddata->clocks[SYSC_ICK];
1477 /* fallthrough */
1478 case 1:
1479 fck = ddata->clocks[SYSC_FCK];
1480 break;
1481 case 0:
1482 return 0;
1483 }
1484
1485 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
1486 if (!error || error == -ENODEV)
1487 return 0;
1488
1489 return error;
1490}
1491
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001492/*
1493 * Note that pdata->init_module() typically does a reset first. After
1494 * pdata->init_module() is done, PM runtime can be used for the interconnect
1495 * target module.
1496 */
1497static int sysc_legacy_init(struct sysc *ddata)
1498{
1499 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1500 int error;
1501
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001502 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001503 return 0;
1504
1505 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
1506 if (error == -EEXIST)
1507 error = 0;
1508
1509 return error;
1510}
1511
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001512/**
1513 * sysc_rstctrl_reset_deassert - deassert rstctrl reset
1514 * @ddata: device driver data
1515 * @reset: reset before deassert
1516 *
1517 * A module can have both OCP softreset control and external rstctrl.
1518 * If more complicated rstctrl resets are needed, please handle these
1519 * directly from the child device driver and map only the module reset
1520 * for the parent interconnect target module device.
1521 *
1522 * Automatic reset of the module on init can be skipped with the
1523 * "ti,no-reset-on-init" device tree property.
1524 */
1525static int sysc_rstctrl_reset_deassert(struct sysc *ddata, bool reset)
1526{
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001527 int error, val;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001528
1529 if (!ddata->rsts)
1530 return 0;
1531
1532 if (reset) {
1533 error = reset_control_assert(ddata->rsts);
1534 if (error)
1535 return error;
1536 }
1537
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001538 error = reset_control_deassert(ddata->rsts);
1539 if (error == -EEXIST)
1540 return 0;
1541
1542 error = readx_poll_timeout(reset_control_status, ddata->rsts, val,
1543 val == 0, 100, MAX_MODULE_SOFTRESET_WAIT);
1544
1545 return error;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001546}
1547
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001548/*
1549 * Note that the caller must ensure the interconnect target module is enabled
1550 * before calling reset. Otherwise reset will not complete.
1551 */
Faiz Abbas596e7952018-07-09 22:18:39 +05301552static int sysc_reset(struct sysc *ddata)
1553{
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001554 int sysc_offset, syss_offset, sysc_val, rstval, quirks, error = 0;
1555 u32 sysc_mask, syss_done;
Faiz Abbas596e7952018-07-09 22:18:39 +05301556
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001557 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
1558 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
1559 quirks = ddata->cfg.quirks;
1560
1561 if (ddata->legacy_mode || sysc_offset < 0 ||
1562 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05301563 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
1564 return 0;
1565
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001566 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05301567
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001568 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
1569 syss_done = 0;
1570 else
1571 syss_done = ddata->cfg.syss_mask;
1572
Tony Lindgren4e23be42019-06-10 04:48:05 -07001573 if (ddata->clk_disable_quirk)
1574 ddata->clk_disable_quirk(ddata);
1575
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001576 sysc_val = sysc_read_sysconfig(ddata);
1577 sysc_val |= sysc_mask;
1578 sysc_write(ddata, sysc_offset, sysc_val);
Faiz Abbas596e7952018-07-09 22:18:39 +05301579
Tony Lindgren4e23be42019-06-10 04:48:05 -07001580 if (ddata->clk_enable_quirk)
1581 ddata->clk_enable_quirk(ddata);
1582
Faiz Abbas596e7952018-07-09 22:18:39 +05301583 /* Poll on reset status */
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001584 if (syss_offset >= 0) {
1585 error = readx_poll_timeout(sysc_read_sysstatus, ddata, rstval,
1586 (rstval & ddata->cfg.syss_mask) ==
1587 syss_done,
1588 100, MAX_MODULE_SOFTRESET_WAIT);
Faiz Abbas596e7952018-07-09 22:18:39 +05301589
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001590 } else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS) {
1591 error = readx_poll_timeout(sysc_read_sysconfig, ddata, rstval,
1592 !(rstval & sysc_mask),
1593 100, MAX_MODULE_SOFTRESET_WAIT);
1594 }
1595
Tony Lindgren4e23be42019-06-10 04:48:05 -07001596 if (ddata->reset_done_quirk)
1597 ddata->reset_done_quirk(ddata);
1598
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001599 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05301600}
1601
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001602/*
1603 * At this point the module is configured enough to read the revision but
1604 * module may not be completely configured yet to use PM runtime. Enable
1605 * all clocks directly during init to configure the quirks needed for PM
1606 * runtime based on the revision register.
1607 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08001608static int sysc_init_module(struct sysc *ddata)
1609{
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001610 int error = 0;
1611 bool manage_clocks = true;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001612
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001613 error = sysc_rstctrl_reset_deassert(ddata, false);
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001614 if (error)
1615 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001616
Tony Lindgren386cb762019-03-22 07:49:30 -07001617 if (ddata->cfg.quirks &
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001618 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))
1619 manage_clocks = false;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001620
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001621 error = sysc_clockdomain_init(ddata);
1622 if (error)
1623 return error;
1624
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001625 if (manage_clocks) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001626 sysc_clkdm_deny_idle(ddata);
1627
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001628 error = sysc_enable_opt_clocks(ddata);
1629 if (error)
1630 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001631
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001632 error = sysc_enable_main_clocks(ddata);
1633 if (error)
1634 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05301635 }
1636
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001637 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
1638 error = sysc_rstctrl_reset_deassert(ddata, true);
1639 if (error)
1640 goto err_main_clocks;
1641 }
1642
Tony Lindgren566a9b052017-12-15 09:41:19 -08001643 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001644 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001645 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001646
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001647 if (ddata->legacy_mode) {
1648 error = sysc_legacy_init(ddata);
1649 if (error)
1650 goto err_main_clocks;
1651 }
1652
1653 if (!ddata->legacy_mode && manage_clocks) {
1654 error = sysc_enable_module(ddata->dev);
1655 if (error)
1656 goto err_main_clocks;
1657 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001658
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001659 error = sysc_reset(ddata);
1660 if (error)
1661 dev_err(ddata->dev, "Reset failed with %d\n", error);
1662
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001663 if (!ddata->legacy_mode && manage_clocks)
1664 sysc_disable_module(ddata->dev);
1665
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001666err_main_clocks:
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001667 if (manage_clocks)
1668 sysc_disable_main_clocks(ddata);
1669err_opt_clocks:
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001670 if (manage_clocks) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001671 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001672 sysc_clkdm_allow_idle(ddata);
1673 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001674
1675 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001676}
1677
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001678static int sysc_init_sysc_mask(struct sysc *ddata)
1679{
1680 struct device_node *np = ddata->dev->of_node;
1681 int error;
1682 u32 val;
1683
1684 error = of_property_read_u32(np, "ti,sysc-mask", &val);
1685 if (error)
1686 return 0;
1687
Tony Lindgrene212abd2019-07-22 03:44:52 -07001688 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001689
1690 return 0;
1691}
1692
1693static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
1694 const char *name)
1695{
1696 struct device_node *np = ddata->dev->of_node;
1697 struct property *prop;
1698 const __be32 *p;
1699 u32 val;
1700
1701 of_property_for_each_u32(np, name, prop, p, val) {
1702 if (val >= SYSC_NR_IDLEMODES) {
1703 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
1704 return -EINVAL;
1705 }
1706 *idlemodes |= (1 << val);
1707 }
1708
1709 return 0;
1710}
1711
1712static int sysc_init_idlemodes(struct sysc *ddata)
1713{
1714 int error;
1715
1716 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
1717 "ti,sysc-midle");
1718 if (error)
1719 return error;
1720
1721 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
1722 "ti,sysc-sidle");
1723 if (error)
1724 return error;
1725
1726 return 0;
1727}
1728
1729/*
1730 * Only some devices on omap4 and later have SYSCONFIG reset done
1731 * bit. We can detect this if there is no SYSSTATUS at all, or the
1732 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
1733 * have multiple bits for the child devices like OHCI and EHCI.
1734 * Depends on SYSC being parsed first.
1735 */
1736static int sysc_init_syss_mask(struct sysc *ddata)
1737{
1738 struct device_node *np = ddata->dev->of_node;
1739 int error;
1740 u32 val;
1741
1742 error = of_property_read_u32(np, "ti,syss-mask", &val);
1743 if (error) {
1744 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
1745 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
1746 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1747 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1748
1749 return 0;
1750 }
1751
1752 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1753 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1754
1755 ddata->cfg.syss_mask = val;
1756
1757 return 0;
1758}
1759
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001760/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001761 * Many child device drivers need to have fck and opt clocks available
1762 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001763 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001764static int sysc_child_add_named_clock(struct sysc *ddata,
1765 struct device *child,
1766 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001767{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001768 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001769 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001770 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001771
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001772 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001773 return 0;
1774
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001775 clk = clk_get(child, name);
1776 if (!IS_ERR(clk)) {
1777 clk_put(clk);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001778
1779 return -EEXIST;
1780 }
1781
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001782 clk = clk_get(ddata->dev, name);
1783 if (IS_ERR(clk))
1784 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001785
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001786 l = clkdev_create(clk, name, dev_name(child));
1787 if (!l)
1788 error = -ENOMEM;
1789
1790 clk_put(clk);
1791
1792 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001793}
1794
Tony Lindgren09dfe582018-04-16 10:25:52 -07001795static int sysc_child_add_clocks(struct sysc *ddata,
1796 struct device *child)
1797{
1798 int i, error;
1799
1800 for (i = 0; i < ddata->nr_clocks; i++) {
1801 error = sysc_child_add_named_clock(ddata,
1802 child,
1803 ddata->clock_roles[i]);
1804 if (error && error != -EEXIST) {
1805 dev_err(ddata->dev, "could not add child clock %s: %i\n",
1806 ddata->clock_roles[i], error);
1807
1808 return error;
1809 }
1810 }
1811
1812 return 0;
1813}
1814
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001815static struct device_type sysc_device_type = {
1816};
1817
1818static struct sysc *sysc_child_to_parent(struct device *dev)
1819{
1820 struct device *parent = dev->parent;
1821
1822 if (!parent || parent->type != &sysc_device_type)
1823 return NULL;
1824
1825 return dev_get_drvdata(parent);
1826}
1827
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001828static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
1829{
1830 struct sysc *ddata;
1831 int error;
1832
1833 ddata = sysc_child_to_parent(dev);
1834
1835 error = pm_generic_runtime_suspend(dev);
1836 if (error)
1837 return error;
1838
1839 if (!ddata->enabled)
1840 return 0;
1841
1842 return sysc_runtime_suspend(ddata->dev);
1843}
1844
1845static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
1846{
1847 struct sysc *ddata;
1848 int error;
1849
1850 ddata = sysc_child_to_parent(dev);
1851
1852 if (!ddata->enabled) {
1853 error = sysc_runtime_resume(ddata->dev);
1854 if (error < 0)
1855 dev_err(ddata->dev,
1856 "%s error: %i\n", __func__, error);
1857 }
1858
1859 return pm_generic_runtime_resume(dev);
1860}
1861
1862#ifdef CONFIG_PM_SLEEP
1863static int sysc_child_suspend_noirq(struct device *dev)
1864{
1865 struct sysc *ddata;
1866 int error;
1867
1868 ddata = sysc_child_to_parent(dev);
1869
Tony Lindgrenef55f822018-04-16 10:27:15 -07001870 dev_dbg(ddata->dev, "%s %s\n", __func__,
1871 ddata->name ? ddata->name : "");
1872
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001873 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001874 if (error) {
1875 dev_err(dev, "%s error at %i: %i\n",
1876 __func__, __LINE__, error);
1877
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001878 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001879 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001880
1881 if (!pm_runtime_status_suspended(dev)) {
1882 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001883 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07001884 dev_dbg(dev, "%s busy at %i: %i\n",
1885 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001886
Tony Lindgren4f3530f2018-08-08 01:07:06 -07001887 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001888 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001889
1890 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001891 if (error) {
1892 dev_err(dev, "%s error at %i: %i\n",
1893 __func__, __LINE__, error);
1894
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001895 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001896 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001897
1898 ddata->child_needs_resume = true;
1899 }
1900
1901 return 0;
1902}
1903
1904static int sysc_child_resume_noirq(struct device *dev)
1905{
1906 struct sysc *ddata;
1907 int error;
1908
1909 ddata = sysc_child_to_parent(dev);
1910
Tony Lindgrenef55f822018-04-16 10:27:15 -07001911 dev_dbg(ddata->dev, "%s %s\n", __func__,
1912 ddata->name ? ddata->name : "");
1913
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001914 if (ddata->child_needs_resume) {
1915 ddata->child_needs_resume = false;
1916
1917 error = sysc_runtime_resume(ddata->dev);
1918 if (error)
1919 dev_err(ddata->dev,
1920 "%s runtime resume error: %i\n",
1921 __func__, error);
1922
1923 error = pm_generic_runtime_resume(dev);
1924 if (error)
1925 dev_err(ddata->dev,
1926 "%s generic runtime resume: %i\n",
1927 __func__, error);
1928 }
1929
1930 return pm_generic_resume_noirq(dev);
1931}
1932#endif
1933
Tony Lindgrenb7182b42019-03-21 11:00:21 -07001934static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001935 .ops = {
1936 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
1937 sysc_child_runtime_resume,
1938 NULL)
1939 USE_PLATFORM_PM_SLEEP_OPS
1940 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
1941 sysc_child_resume_noirq)
1942 }
1943};
1944
1945/**
1946 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
1947 * @ddata: device driver data
1948 * @child: child device driver
1949 *
1950 * Allow idle for child devices as done with _od_runtime_suspend().
1951 * Otherwise many child devices will not idle because of the permanent
1952 * parent usecount set in pm_runtime_irq_safe().
1953 *
1954 * Note that the long term solution is to just modify the child device
1955 * drivers to not set pm_runtime_irq_safe() and then this can be just
1956 * dropped.
1957 */
1958static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
1959{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001960 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
1961 dev_pm_domain_set(child, &sysc_child_pm_domain);
1962}
1963
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001964static int sysc_notifier_call(struct notifier_block *nb,
1965 unsigned long event, void *device)
1966{
1967 struct device *dev = device;
1968 struct sysc *ddata;
1969 int error;
1970
1971 ddata = sysc_child_to_parent(dev);
1972 if (!ddata)
1973 return NOTIFY_DONE;
1974
1975 switch (event) {
1976 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07001977 error = sysc_child_add_clocks(ddata, dev);
1978 if (error)
1979 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001980 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001981 break;
1982 default:
1983 break;
1984 }
1985
1986 return NOTIFY_DONE;
1987}
1988
1989static struct notifier_block sysc_nb = {
1990 .notifier_call = sysc_notifier_call,
1991};
1992
Tony Lindgren566a9b052017-12-15 09:41:19 -08001993/* Device tree configured quirks */
1994struct sysc_dts_quirk {
1995 const char *name;
1996 u32 mask;
1997};
1998
1999static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2000 { .name = "ti,no-idle-on-init",
2001 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2002 { .name = "ti,no-reset-on-init",
2003 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002004 { .name = "ti,no-idle",
2005 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002006};
2007
Tony Lindgren4014c082018-12-10 14:11:26 -08002008static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2009 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002010{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002011 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002012 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002013
2014 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002015 const char *name = sysc_dts_quirks[i].name;
2016
2017 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002018 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002019 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002020
2021 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002022 if (is_child) {
2023 dev_warn(ddata->dev,
2024 "dts flag should be at module level for %s\n",
2025 name);
2026 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002027 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002028}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002029
Tony Lindgren4014c082018-12-10 14:11:26 -08002030static int sysc_init_dts_quirks(struct sysc *ddata)
2031{
2032 struct device_node *np = ddata->dev->of_node;
2033 int error;
2034 u32 val;
2035
2036 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2037
2038 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002039 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2040 if (!error) {
2041 if (val > 255) {
2042 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2043 val);
2044 }
2045
2046 ddata->cfg.srst_udelay = (u8)val;
2047 }
2048
2049 return 0;
2050}
2051
Tony Lindgren0eecc632017-10-10 14:23:43 -07002052static void sysc_unprepare(struct sysc *ddata)
2053{
2054 int i;
2055
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002056 if (!ddata->clocks)
2057 return;
2058
Tony Lindgren0eecc632017-10-10 14:23:43 -07002059 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2060 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2061 clk_unprepare(ddata->clocks[i]);
2062 }
2063}
2064
Tony Lindgren70a65242017-12-15 09:41:09 -08002065/*
2066 * Common sysc register bits found on omap2, also known as type1
2067 */
2068static const struct sysc_regbits sysc_regbits_omap2 = {
2069 .dmadisable_shift = -ENODEV,
2070 .midle_shift = 12,
2071 .sidle_shift = 3,
2072 .clkact_shift = 8,
2073 .emufree_shift = 5,
2074 .enwkup_shift = 2,
2075 .srst_shift = 1,
2076 .autoidle_shift = 0,
2077};
2078
2079static const struct sysc_capabilities sysc_omap2 = {
2080 .type = TI_SYSC_OMAP2,
2081 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2082 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2083 SYSC_OMAP2_AUTOIDLE,
2084 .regbits = &sysc_regbits_omap2,
2085};
2086
2087/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2088static const struct sysc_capabilities sysc_omap2_timer = {
2089 .type = TI_SYSC_OMAP2_TIMER,
2090 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2091 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2092 SYSC_OMAP2_AUTOIDLE,
2093 .regbits = &sysc_regbits_omap2,
2094 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2095};
2096
2097/*
2098 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2099 * with different sidle position
2100 */
2101static const struct sysc_regbits sysc_regbits_omap3_sham = {
2102 .dmadisable_shift = -ENODEV,
2103 .midle_shift = -ENODEV,
2104 .sidle_shift = 4,
2105 .clkact_shift = -ENODEV,
2106 .enwkup_shift = -ENODEV,
2107 .srst_shift = 1,
2108 .autoidle_shift = 0,
2109 .emufree_shift = -ENODEV,
2110};
2111
2112static const struct sysc_capabilities sysc_omap3_sham = {
2113 .type = TI_SYSC_OMAP3_SHAM,
2114 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2115 .regbits = &sysc_regbits_omap3_sham,
2116};
2117
2118/*
2119 * AES register bits found on omap3 and later, a variant of
2120 * sysc_regbits_omap2 with different sidle position
2121 */
2122static const struct sysc_regbits sysc_regbits_omap3_aes = {
2123 .dmadisable_shift = -ENODEV,
2124 .midle_shift = -ENODEV,
2125 .sidle_shift = 6,
2126 .clkact_shift = -ENODEV,
2127 .enwkup_shift = -ENODEV,
2128 .srst_shift = 1,
2129 .autoidle_shift = 0,
2130 .emufree_shift = -ENODEV,
2131};
2132
2133static const struct sysc_capabilities sysc_omap3_aes = {
2134 .type = TI_SYSC_OMAP3_AES,
2135 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2136 .regbits = &sysc_regbits_omap3_aes,
2137};
2138
2139/*
2140 * Common sysc register bits found on omap4, also known as type2
2141 */
2142static const struct sysc_regbits sysc_regbits_omap4 = {
2143 .dmadisable_shift = 16,
2144 .midle_shift = 4,
2145 .sidle_shift = 2,
2146 .clkact_shift = -ENODEV,
2147 .enwkup_shift = -ENODEV,
2148 .emufree_shift = 1,
2149 .srst_shift = 0,
2150 .autoidle_shift = -ENODEV,
2151};
2152
2153static const struct sysc_capabilities sysc_omap4 = {
2154 .type = TI_SYSC_OMAP4,
2155 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2156 SYSC_OMAP4_SOFTRESET,
2157 .regbits = &sysc_regbits_omap4,
2158};
2159
2160static const struct sysc_capabilities sysc_omap4_timer = {
2161 .type = TI_SYSC_OMAP4_TIMER,
2162 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2163 SYSC_OMAP4_SOFTRESET,
2164 .regbits = &sysc_regbits_omap4,
2165};
2166
2167/*
2168 * Common sysc register bits found on omap4, also known as type3
2169 */
2170static const struct sysc_regbits sysc_regbits_omap4_simple = {
2171 .dmadisable_shift = -ENODEV,
2172 .midle_shift = 2,
2173 .sidle_shift = 0,
2174 .clkact_shift = -ENODEV,
2175 .enwkup_shift = -ENODEV,
2176 .srst_shift = -ENODEV,
2177 .emufree_shift = -ENODEV,
2178 .autoidle_shift = -ENODEV,
2179};
2180
2181static const struct sysc_capabilities sysc_omap4_simple = {
2182 .type = TI_SYSC_OMAP4_SIMPLE,
2183 .regbits = &sysc_regbits_omap4_simple,
2184};
2185
2186/*
2187 * SmartReflex sysc found on omap34xx
2188 */
2189static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2190 .dmadisable_shift = -ENODEV,
2191 .midle_shift = -ENODEV,
2192 .sidle_shift = -ENODEV,
2193 .clkact_shift = 20,
2194 .enwkup_shift = -ENODEV,
2195 .srst_shift = -ENODEV,
2196 .emufree_shift = -ENODEV,
2197 .autoidle_shift = -ENODEV,
2198};
2199
2200static const struct sysc_capabilities sysc_34xx_sr = {
2201 .type = TI_SYSC_OMAP34XX_SR,
2202 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2203 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002204 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2205 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002206};
2207
2208/*
2209 * SmartReflex sysc found on omap36xx and later
2210 */
2211static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2212 .dmadisable_shift = -ENODEV,
2213 .midle_shift = -ENODEV,
2214 .sidle_shift = 24,
2215 .clkact_shift = -ENODEV,
2216 .enwkup_shift = 26,
2217 .srst_shift = -ENODEV,
2218 .emufree_shift = -ENODEV,
2219 .autoidle_shift = -ENODEV,
2220};
2221
2222static const struct sysc_capabilities sysc_36xx_sr = {
2223 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002224 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002225 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002226 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002227};
2228
2229static const struct sysc_capabilities sysc_omap4_sr = {
2230 .type = TI_SYSC_OMAP4_SR,
2231 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002232 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002233};
2234
2235/*
2236 * McASP register bits found on omap4 and later
2237 */
2238static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2239 .dmadisable_shift = -ENODEV,
2240 .midle_shift = -ENODEV,
2241 .sidle_shift = 0,
2242 .clkact_shift = -ENODEV,
2243 .enwkup_shift = -ENODEV,
2244 .srst_shift = -ENODEV,
2245 .emufree_shift = -ENODEV,
2246 .autoidle_shift = -ENODEV,
2247};
2248
2249static const struct sysc_capabilities sysc_omap4_mcasp = {
2250 .type = TI_SYSC_OMAP4_MCASP,
2251 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002252 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2253};
2254
2255/*
2256 * McASP found on dra7 and later
2257 */
2258static const struct sysc_capabilities sysc_dra7_mcasp = {
2259 .type = TI_SYSC_OMAP4_SIMPLE,
2260 .regbits = &sysc_regbits_omap4_simple,
2261 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002262};
2263
2264/*
2265 * FS USB host found on omap4 and later
2266 */
2267static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2268 .dmadisable_shift = -ENODEV,
2269 .midle_shift = -ENODEV,
2270 .sidle_shift = 24,
2271 .clkact_shift = -ENODEV,
2272 .enwkup_shift = 26,
2273 .srst_shift = -ENODEV,
2274 .emufree_shift = -ENODEV,
2275 .autoidle_shift = -ENODEV,
2276};
2277
2278static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2279 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2280 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2281 .regbits = &sysc_regbits_omap4_usb_host_fs,
2282};
2283
Faiz Abbas7f35e632018-07-09 22:18:38 +05302284static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2285 .dmadisable_shift = -ENODEV,
2286 .midle_shift = -ENODEV,
2287 .sidle_shift = -ENODEV,
2288 .clkact_shift = -ENODEV,
2289 .enwkup_shift = 4,
2290 .srst_shift = 0,
2291 .emufree_shift = -ENODEV,
2292 .autoidle_shift = -ENODEV,
2293};
2294
2295static const struct sysc_capabilities sysc_dra7_mcan = {
2296 .type = TI_SYSC_DRA7_MCAN,
2297 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2298 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002299 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302300};
2301
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002302static int sysc_init_pdata(struct sysc *ddata)
2303{
2304 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002305 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002306
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002307 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002308 return 0;
2309
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002310 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2311 if (!mdata)
2312 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002313
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002314 if (ddata->legacy_mode) {
2315 mdata->name = ddata->legacy_mode;
2316 mdata->module_pa = ddata->module_pa;
2317 mdata->module_size = ddata->module_size;
2318 mdata->offsets = ddata->offsets;
2319 mdata->nr_offsets = SYSC_MAX_REGS;
2320 mdata->cap = ddata->cap;
2321 mdata->cfg = &ddata->cfg;
2322 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002323
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002324 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002325
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002326 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002327}
2328
Tony Lindgren70a65242017-12-15 09:41:09 -08002329static int sysc_init_match(struct sysc *ddata)
2330{
2331 const struct sysc_capabilities *cap;
2332
2333 cap = of_device_get_match_data(ddata->dev);
2334 if (!cap)
2335 return -EINVAL;
2336
2337 ddata->cap = cap;
2338 if (ddata->cap)
2339 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2340
2341 return 0;
2342}
2343
Tony Lindgren76f0f772018-02-23 08:28:45 -08002344static void ti_sysc_idle(struct work_struct *work)
2345{
2346 struct sysc *ddata;
2347
2348 ddata = container_of(work, struct sysc, idle_work.work);
2349
2350 if (pm_runtime_active(ddata->dev))
2351 pm_runtime_put_sync(ddata->dev);
2352}
2353
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002354static const struct of_device_id sysc_match_table[] = {
2355 { .compatible = "simple-bus", },
2356 { /* sentinel */ },
2357};
2358
Tony Lindgren0eecc632017-10-10 14:23:43 -07002359static int sysc_probe(struct platform_device *pdev)
2360{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002361 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002362 struct sysc *ddata;
2363 int error;
2364
2365 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
2366 if (!ddata)
2367 return -ENOMEM;
2368
2369 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002370 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002371
Tony Lindgren70a65242017-12-15 09:41:09 -08002372 error = sysc_init_match(ddata);
2373 if (error)
2374 return error;
2375
Tony Lindgren566a9b052017-12-15 09:41:19 -08002376 error = sysc_init_dts_quirks(ddata);
2377 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002378 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002379
Tony Lindgren0eecc632017-10-10 14:23:43 -07002380 error = sysc_map_and_check_registers(ddata);
2381 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002382 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07002383
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002384 error = sysc_init_sysc_mask(ddata);
2385 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002386 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002387
2388 error = sysc_init_idlemodes(ddata);
2389 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002390 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002391
2392 error = sysc_init_syss_mask(ddata);
2393 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002394 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002395
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002396 error = sysc_init_pdata(ddata);
2397 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002398 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002399
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07002400 sysc_init_early_quirks(ddata);
2401
2402 error = sysc_get_clocks(ddata);
2403 if (error)
2404 return error;
2405
Tony Lindgren50622362018-04-16 10:20:27 -07002406 error = sysc_init_resets(ddata);
2407 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002408 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002409
2410 error = sysc_init_module(ddata);
2411 if (error)
2412 goto unprepare;
2413
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002414 pm_runtime_enable(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002415 error = pm_runtime_get_sync(ddata->dev);
2416 if (error < 0) {
2417 pm_runtime_put_noidle(ddata->dev);
2418 pm_runtime_disable(ddata->dev);
2419 goto unprepare;
2420 }
2421
Tony Lindgren0eecc632017-10-10 14:23:43 -07002422 sysc_show_registers(ddata);
2423
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002424 ddata->dev->type = &sysc_device_type;
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002425 error = of_platform_populate(ddata->dev->of_node, sysc_match_table,
2426 pdata ? pdata->auxdata : NULL,
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002427 ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002428 if (error)
2429 goto err;
2430
Tony Lindgren76f0f772018-02-23 08:28:45 -08002431 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
2432
2433 /* At least earlycon won't survive without deferred idle */
2434 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE_ON_INIT |
2435 SYSC_QUIRK_NO_RESET_ON_INIT)) {
2436 schedule_delayed_work(&ddata->idle_work, 3000);
2437 } else {
2438 pm_runtime_put(&pdev->dev);
2439 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07002440
Tony Lindgren50622362018-04-16 10:20:27 -07002441 if (!of_get_available_child_count(ddata->dev->of_node))
Tony Lindgren8383e252019-05-27 04:51:56 -07002442 ddata->disable_on_idle = true;
Tony Lindgren50622362018-04-16 10:20:27 -07002443
Tony Lindgren0eecc632017-10-10 14:23:43 -07002444 return 0;
2445
2446err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07002447 pm_runtime_put_sync(&pdev->dev);
2448 pm_runtime_disable(&pdev->dev);
2449unprepare:
2450 sysc_unprepare(ddata);
2451
2452 return error;
2453}
2454
Tony Lindgren684be5a2017-10-13 10:48:40 -07002455static int sysc_remove(struct platform_device *pdev)
2456{
2457 struct sysc *ddata = platform_get_drvdata(pdev);
2458 int error;
2459
Tony Lindgren76f0f772018-02-23 08:28:45 -08002460 cancel_delayed_work_sync(&ddata->idle_work);
2461
Tony Lindgren684be5a2017-10-13 10:48:40 -07002462 error = pm_runtime_get_sync(ddata->dev);
2463 if (error < 0) {
2464 pm_runtime_put_noidle(ddata->dev);
2465 pm_runtime_disable(ddata->dev);
2466 goto unprepare;
2467 }
2468
2469 of_platform_depopulate(&pdev->dev);
2470
Tony Lindgren684be5a2017-10-13 10:48:40 -07002471 pm_runtime_put_sync(&pdev->dev);
2472 pm_runtime_disable(&pdev->dev);
Tony Lindgren50622362018-04-16 10:20:27 -07002473 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07002474
2475unprepare:
2476 sysc_unprepare(ddata);
2477
2478 return 0;
2479}
2480
Tony Lindgren0eecc632017-10-10 14:23:43 -07002481static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08002482 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
2483 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
2484 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
2485 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
2486 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
2487 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
2488 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
2489 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
2490 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
2491 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
2492 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08002493 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08002494 { .compatible = "ti,sysc-usb-host-fs",
2495 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05302496 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07002497 { },
2498};
2499MODULE_DEVICE_TABLE(of, sysc_match);
2500
2501static struct platform_driver sysc_driver = {
2502 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07002503 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07002504 .driver = {
2505 .name = "ti-sysc",
2506 .of_match_table = sysc_match,
2507 .pm = &sysc_pm_ops,
2508 },
2509};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002510
2511static int __init sysc_init(void)
2512{
2513 bus_register_notifier(&platform_bus_type, &sysc_nb);
2514
2515 return platform_driver_register(&sysc_driver);
2516}
2517module_init(sysc_init);
2518
2519static void __exit sysc_exit(void)
2520{
2521 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
2522 platform_driver_unregister(&sysc_driver);
2523}
2524module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002525
2526MODULE_DESCRIPTION("TI sysc interconnect target driver");
2527MODULE_LICENSE("GPL v2");