blob: 082fb15fa17440ea2a4172e4a1fe99f482910530 [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
Suman Annab58056d2019-08-13 04:13:32 -070057 * @mdata: ti-sysc to hwmod translation data for a module
Tony Lindgren0eecc632017-10-10 14:23:43 -070058 * @clocks: clocks used by the interconnect target module
Tony Lindgren09dfe582018-04-16 10:25:52 -070059 * @clock_roles: clock role names for the found clocks
60 * @nr_clocks: number of clocks used by the interconnect target module
Suman Annab58056d2019-08-13 04:13:32 -070061 * @rsts: resets used by the interconnect target module
Tony Lindgren0eecc632017-10-10 14:23:43 -070062 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -080063 * @cap: interconnect target module capabilities
64 * @cfg: interconnect target module configuration
Suman Annab58056d2019-08-13 04:13:32 -070065 * @cookie: data used by legacy platform callbacks
Tony Lindgren566a9b052017-12-15 09:41:19 -080066 * @name: name if available
67 * @revision: interconnect target module revision
Suman Annab58056d2019-08-13 04:13:32 -070068 * @enabled: sysc runtime enabled status
Tony Lindgren62020f22018-02-22 13:59:44 -080069 * @needs_resume: runtime resume needed on resume from suspend
Suman Annab58056d2019-08-13 04:13:32 -070070 * @child_needs_resume: runtime resume needed for child on resume from suspend
71 * @disable_on_idle: status flag used for disabling modules with resets
72 * @idle_work: work structure used to perform delayed idle on a module
Tony Lindgren4e23be42019-06-10 04:48:05 -070073 * @clk_enable_quirk: module specific clock enable quirk
74 * @clk_disable_quirk: module specific clock disable quirk
75 * @reset_done_quirk: module specific reset done quirk
Tony Lindgren0eecc632017-10-10 14:23:43 -070076 */
77struct sysc {
78 struct device *dev;
79 u64 module_pa;
80 u32 module_size;
81 void __iomem *module_va;
82 int offsets[SYSC_MAX_REGS];
Tony Lindgrena3e92e72019-03-21 11:00:21 -070083 struct ti_sysc_module_data *mdata;
Tony Lindgren09dfe582018-04-16 10:25:52 -070084 struct clk **clocks;
85 const char **clock_roles;
86 int nr_clocks;
Tony Lindgren50622362018-04-16 10:20:27 -070087 struct reset_control *rsts;
Tony Lindgren0eecc632017-10-10 14:23:43 -070088 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -080089 const struct sysc_capabilities *cap;
90 struct sysc_config cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -080091 struct ti_sysc_cookie cookie;
Tony Lindgren566a9b052017-12-15 09:41:19 -080092 const char *name;
93 u32 revision;
Tony Lindgren8383e252019-05-27 04:51:56 -070094 unsigned int enabled:1;
95 unsigned int needs_resume:1;
96 unsigned int child_needs_resume:1;
Tony Lindgren76f0f772018-02-23 08:28:45 -080097 struct delayed_work idle_work;
Tony Lindgren4e23be42019-06-10 04:48:05 -070098 void (*clk_enable_quirk)(struct sysc *sysc);
99 void (*clk_disable_quirk)(struct sysc *sysc);
100 void (*reset_done_quirk)(struct sysc *sysc);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700101};
102
Tony Lindgren4014c082018-12-10 14:11:26 -0800103static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
104 bool is_child);
105
Tony Lindgrenb7182b42019-03-21 11:00:21 -0700106static void sysc_write(struct sysc *ddata, int offset, u32 value)
Faiz Abbas596e7952018-07-09 22:18:39 +0530107{
Tony Lindgren5aa91292019-05-27 04:51:53 -0700108 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
109 writew_relaxed(value & 0xffff, ddata->module_va + offset);
110
111 /* Only i2c revision has LO and HI register with stride of 4 */
112 if (ddata->offsets[SYSC_REVISION] >= 0 &&
113 offset == ddata->offsets[SYSC_REVISION]) {
114 u16 hi = value >> 16;
115
116 writew_relaxed(hi, ddata->module_va + offset + 4);
117 }
118
119 return;
120 }
121
Faiz Abbas596e7952018-07-09 22:18:39 +0530122 writel_relaxed(value, ddata->module_va + offset);
123}
124
Tony Lindgren566a9b052017-12-15 09:41:19 -0800125static u32 sysc_read(struct sysc *ddata, int offset)
126{
127 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
128 u32 val;
129
130 val = readw_relaxed(ddata->module_va + offset);
Tony Lindgren5aa91292019-05-27 04:51:53 -0700131
132 /* Only i2c revision has LO and HI register with stride of 4 */
133 if (ddata->offsets[SYSC_REVISION] >= 0 &&
134 offset == ddata->offsets[SYSC_REVISION]) {
135 u16 tmp = readw_relaxed(ddata->module_va + offset + 4);
136
137 val |= tmp << 16;
138 }
Tony Lindgren566a9b052017-12-15 09:41:19 -0800139
140 return val;
141 }
142
143 return readl_relaxed(ddata->module_va + offset);
144}
145
Tony Lindgren09dfe582018-04-16 10:25:52 -0700146static bool sysc_opt_clks_needed(struct sysc *ddata)
147{
148 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
149}
150
Tony Lindgren0eecc632017-10-10 14:23:43 -0700151static u32 sysc_read_revision(struct sysc *ddata)
152{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800153 int offset = ddata->offsets[SYSC_REVISION];
154
155 if (offset < 0)
156 return 0;
157
158 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700159}
160
Tony Lindgrene0db94f2019-05-27 04:51:53 -0700161static u32 sysc_read_sysconfig(struct sysc *ddata)
162{
163 int offset = ddata->offsets[SYSC_SYSCONFIG];
164
165 if (offset < 0)
166 return 0;
167
168 return sysc_read(ddata, offset);
169}
170
171static u32 sysc_read_sysstatus(struct sysc *ddata)
172{
173 int offset = ddata->offsets[SYSC_SYSSTATUS];
174
175 if (offset < 0)
176 return 0;
177
178 return sysc_read(ddata, offset);
179}
180
Tony Lindgrena54275f2019-03-21 11:00:21 -0700181static int sysc_add_named_clock_from_child(struct sysc *ddata,
182 const char *name,
183 const char *optfck_name)
184{
185 struct device_node *np = ddata->dev->of_node;
186 struct device_node *child;
187 struct clk_lookup *cl;
188 struct clk *clock;
189 const char *n;
190
191 if (name)
192 n = name;
193 else
194 n = optfck_name;
195
196 /* Does the clock alias already exist? */
197 clock = of_clk_get_by_name(np, n);
198 if (!IS_ERR(clock)) {
199 clk_put(clock);
200
201 return 0;
202 }
203
204 child = of_get_next_available_child(np, NULL);
205 if (!child)
206 return -ENODEV;
207
208 clock = devm_get_clk_from_child(ddata->dev, child, name);
209 if (IS_ERR(clock))
210 return PTR_ERR(clock);
211
212 /*
213 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
214 * limit for clk_get(). If cl ever needs to be freed, it should be done
215 * with clkdev_drop().
216 */
217 cl = kcalloc(1, sizeof(*cl), GFP_KERNEL);
218 if (!cl)
219 return -ENOMEM;
220
221 cl->con_id = n;
222 cl->dev_id = dev_name(ddata->dev);
223 cl->clk = clock;
224 clkdev_add(cl);
225
226 clk_put(clock);
227
228 return 0;
229}
230
231static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
232{
233 const char *optfck_name;
234 int error, index;
235
236 if (ddata->nr_clocks < SYSC_OPTFCK0)
237 index = SYSC_OPTFCK0;
238 else
239 index = ddata->nr_clocks;
240
241 if (name)
242 optfck_name = name;
243 else
244 optfck_name = clock_names[index];
245
246 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
247 if (error)
248 return error;
249
250 ddata->clock_roles[index] = optfck_name;
251 ddata->nr_clocks++;
252
253 return 0;
254}
255
Tony Lindgren09dfe582018-04-16 10:25:52 -0700256static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700257{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700258 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700259
Tony Lindgren09dfe582018-04-16 10:25:52 -0700260 if (!strncmp(clock_names[SYSC_FCK], name, 3))
261 index = SYSC_FCK;
262 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
263 index = SYSC_ICK;
264
265 if (index < 0) {
266 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700267 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700268 index = i;
269 break;
270 }
271 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700272 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700273
274 if (index < 0) {
275 dev_err(ddata->dev, "clock %s not added\n", name);
276 return index;
277 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700278
279 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
280 if (IS_ERR(ddata->clocks[index])) {
281 if (PTR_ERR(ddata->clocks[index]) == -ENOENT)
282 return 0;
283
284 dev_err(ddata->dev, "clock get error for %s: %li\n",
285 name, PTR_ERR(ddata->clocks[index]));
286
287 return PTR_ERR(ddata->clocks[index]);
288 }
289
290 error = clk_prepare(ddata->clocks[index]);
291 if (error) {
292 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
293 name, error);
294
295 return error;
296 }
297
298 return 0;
299}
300
301static int sysc_get_clocks(struct sysc *ddata)
302{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700303 struct device_node *np = ddata->dev->of_node;
304 struct property *prop;
305 const char *name;
306 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700307
Kees Cook20749052018-06-18 10:45:49 -0700308 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700309 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700310 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700311 GFP_KERNEL);
312 if (!ddata->clock_roles)
313 return -ENOMEM;
314
315 of_property_for_each_string(np, "clock-names", prop, name) {
316 if (!strncmp(clock_names[SYSC_FCK], name, 3))
317 nr_fck++;
318 if (!strncmp(clock_names[SYSC_ICK], name, 3))
319 nr_ick++;
320 ddata->clock_roles[ddata->nr_clocks] = name;
321 ddata->nr_clocks++;
322 }
323
324 if (ddata->nr_clocks < 1)
325 return 0;
326
Tony Lindgrena54275f2019-03-21 11:00:21 -0700327 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
328 error = sysc_init_ext_opt_clock(ddata, NULL);
329 if (error)
330 return error;
331 }
332
Tony Lindgren09dfe582018-04-16 10:25:52 -0700333 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
334 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
335
336 return -EINVAL;
337 }
338
339 if (nr_fck > 1 || nr_ick > 1) {
340 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
341
342 return -EINVAL;
343 }
344
Kees Cook20749052018-06-18 10:45:49 -0700345 ddata->clocks = devm_kcalloc(ddata->dev,
346 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700347 GFP_KERNEL);
348 if (!ddata->clocks)
349 return -ENOMEM;
350
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800351 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
352 const char *name = ddata->clock_roles[i];
353
354 if (!name)
355 continue;
356
357 error = sysc_get_one_clock(ddata, name);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700358 if (error && error != -ENOENT)
359 return error;
360 }
361
362 return 0;
363}
364
Tony Lindgrend8789702019-03-21 11:00:21 -0700365static int sysc_enable_main_clocks(struct sysc *ddata)
366{
367 struct clk *clock;
368 int i, error;
369
370 if (!ddata->clocks)
371 return 0;
372
373 for (i = 0; i < SYSC_OPTFCK0; i++) {
374 clock = ddata->clocks[i];
375
376 /* Main clocks may not have ick */
377 if (IS_ERR_OR_NULL(clock))
378 continue;
379
380 error = clk_enable(clock);
381 if (error)
382 goto err_disable;
383 }
384
385 return 0;
386
387err_disable:
388 for (i--; i >= 0; i--) {
389 clock = ddata->clocks[i];
390
391 /* Main clocks may not have ick */
392 if (IS_ERR_OR_NULL(clock))
393 continue;
394
395 clk_disable(clock);
396 }
397
398 return error;
399}
400
401static void sysc_disable_main_clocks(struct sysc *ddata)
402{
403 struct clk *clock;
404 int i;
405
406 if (!ddata->clocks)
407 return;
408
409 for (i = 0; i < SYSC_OPTFCK0; i++) {
410 clock = ddata->clocks[i];
411 if (IS_ERR_OR_NULL(clock))
412 continue;
413
414 clk_disable(clock);
415 }
416}
417
418static int sysc_enable_opt_clocks(struct sysc *ddata)
419{
420 struct clk *clock;
421 int i, error;
422
423 if (!ddata->clocks)
424 return 0;
425
426 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
427 clock = ddata->clocks[i];
428
429 /* Assume no holes for opt clocks */
430 if (IS_ERR_OR_NULL(clock))
431 return 0;
432
433 error = clk_enable(clock);
434 if (error)
435 goto err_disable;
436 }
437
438 return 0;
439
440err_disable:
441 for (i--; i >= 0; i--) {
442 clock = ddata->clocks[i];
443 if (IS_ERR_OR_NULL(clock))
444 continue;
445
446 clk_disable(clock);
447 }
448
449 return error;
450}
451
452static void sysc_disable_opt_clocks(struct sysc *ddata)
453{
454 struct clk *clock;
455 int i;
456
457 if (!ddata->clocks)
458 return;
459
460 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
461 clock = ddata->clocks[i];
462
463 /* Assume no holes for opt clocks */
464 if (IS_ERR_OR_NULL(clock))
465 return;
466
467 clk_disable(clock);
468 }
469}
470
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700471static void sysc_clkdm_deny_idle(struct sysc *ddata)
472{
473 struct ti_sysc_platform_data *pdata;
474
475 if (ddata->legacy_mode)
476 return;
477
478 pdata = dev_get_platdata(ddata->dev);
479 if (pdata && pdata->clkdm_deny_idle)
480 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
481}
482
483static void sysc_clkdm_allow_idle(struct sysc *ddata)
484{
485 struct ti_sysc_platform_data *pdata;
486
487 if (ddata->legacy_mode)
488 return;
489
490 pdata = dev_get_platdata(ddata->dev);
491 if (pdata && pdata->clkdm_allow_idle)
492 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
493}
494
Tony Lindgren0eecc632017-10-10 14:23:43 -0700495/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700496 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700497 * @ddata: device driver data
498 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700499 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700500 */
501static int sysc_init_resets(struct sysc *ddata)
502{
Tony Lindgren50622362018-04-16 10:20:27 -0700503 ddata->rsts =
Tero Kristobb88b862019-08-07 15:46:05 +0300504 devm_reset_control_get_optional_shared(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700505 if (IS_ERR(ddata->rsts))
506 return PTR_ERR(ddata->rsts);
507
Tony Lindgren50622362018-04-16 10:20:27 -0700508 return 0;
509}
510
511/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700512 * sysc_parse_and_check_child_range - parses module IO region from ranges
513 * @ddata: device driver data
514 *
515 * In general we only need rev, syss, and sysc registers and not the whole
516 * module range. But we do want the offsets for these registers from the
517 * module base. This allows us to check them against the legacy hwmod
518 * platform data. Let's also check the ranges are configured properly.
519 */
520static int sysc_parse_and_check_child_range(struct sysc *ddata)
521{
522 struct device_node *np = ddata->dev->of_node;
523 const __be32 *ranges;
524 u32 nr_addr, nr_size;
525 int len, error;
526
527 ranges = of_get_property(np, "ranges", &len);
528 if (!ranges) {
529 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
530
531 return -ENOENT;
532 }
533
534 len /= sizeof(*ranges);
535
536 if (len < 3) {
537 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
538
539 return -EINVAL;
540 }
541
542 error = of_property_read_u32(np, "#address-cells", &nr_addr);
543 if (error)
544 return -ENOENT;
545
546 error = of_property_read_u32(np, "#size-cells", &nr_size);
547 if (error)
548 return -ENOENT;
549
550 if (nr_addr != 1 || nr_size != 1) {
551 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
552
553 return -EINVAL;
554 }
555
556 ranges++;
557 ddata->module_pa = of_translate_address(np, ranges++);
558 ddata->module_size = be32_to_cpup(ranges);
559
Tony Lindgren0eecc632017-10-10 14:23:43 -0700560 return 0;
561}
562
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800563static struct device_node *stdout_path;
564
565static void sysc_init_stdout_path(struct sysc *ddata)
566{
567 struct device_node *np = NULL;
568 const char *uart;
569
570 if (IS_ERR(stdout_path))
571 return;
572
573 if (stdout_path)
574 return;
575
576 np = of_find_node_by_path("/chosen");
577 if (!np)
578 goto err;
579
580 uart = of_get_property(np, "stdout-path", NULL);
581 if (!uart)
582 goto err;
583
584 np = of_find_node_by_path(uart);
585 if (!np)
586 goto err;
587
588 stdout_path = np;
589
590 return;
591
592err:
593 stdout_path = ERR_PTR(-ENODEV);
594}
595
596static void sysc_check_quirk_stdout(struct sysc *ddata,
597 struct device_node *np)
598{
599 sysc_init_stdout_path(ddata);
600 if (np != stdout_path)
601 return;
602
603 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
604 SYSC_QUIRK_NO_RESET_ON_INIT;
605}
606
Tony Lindgren0eecc632017-10-10 14:23:43 -0700607/**
608 * sysc_check_one_child - check child configuration
609 * @ddata: device driver data
610 * @np: child device node
611 *
612 * Let's avoid messy situations where we have new interconnect target
613 * node but children have "ti,hwmods". These belong to the interconnect
614 * target node and are managed by this driver.
615 */
616static int sysc_check_one_child(struct sysc *ddata,
617 struct device_node *np)
618{
619 const char *name;
620
621 name = of_get_property(np, "ti,hwmods", NULL);
622 if (name)
623 dev_warn(ddata->dev, "really a child ti,hwmods property?");
624
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800625 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800626 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800627
Tony Lindgren0eecc632017-10-10 14:23:43 -0700628 return 0;
629}
630
631static int sysc_check_children(struct sysc *ddata)
632{
633 struct device_node *child;
634 int error;
635
636 for_each_child_of_node(ddata->dev->of_node, child) {
637 error = sysc_check_one_child(ddata, child);
638 if (error)
639 return error;
640 }
641
642 return 0;
643}
644
Tony Lindgrena7199e22017-12-15 09:41:14 -0800645/*
646 * So far only I2C uses 16-bit read access with clockactivity with revision
647 * in two registers with stride of 4. We can detect this based on the rev
648 * register size to configure things far enough to be able to properly read
649 * the revision register.
650 */
651static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
652{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800653 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800654 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800655}
656
Tony Lindgren0eecc632017-10-10 14:23:43 -0700657/**
658 * sysc_parse_one - parses the interconnect target module registers
659 * @ddata: device driver data
660 * @reg: register to parse
661 */
662static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
663{
664 struct resource *res;
665 const char *name;
666
667 switch (reg) {
668 case SYSC_REVISION:
669 case SYSC_SYSCONFIG:
670 case SYSC_SYSSTATUS:
671 name = reg_names[reg];
672 break;
673 default:
674 return -EINVAL;
675 }
676
677 res = platform_get_resource_byname(to_platform_device(ddata->dev),
678 IORESOURCE_MEM, name);
679 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700680 ddata->offsets[reg] = -ENODEV;
681
682 return 0;
683 }
684
685 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800686 if (reg == SYSC_REVISION)
687 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700688
689 return 0;
690}
691
692static int sysc_parse_registers(struct sysc *ddata)
693{
694 int i, error;
695
696 for (i = 0; i < SYSC_MAX_REGS; i++) {
697 error = sysc_parse_one(ddata, i);
698 if (error)
699 return error;
700 }
701
702 return 0;
703}
704
705/**
706 * sysc_check_registers - check for misconfigured register overlaps
707 * @ddata: device driver data
708 */
709static int sysc_check_registers(struct sysc *ddata)
710{
711 int i, j, nr_regs = 0, nr_matches = 0;
712
713 for (i = 0; i < SYSC_MAX_REGS; i++) {
714 if (ddata->offsets[i] < 0)
715 continue;
716
717 if (ddata->offsets[i] > (ddata->module_size - 4)) {
718 dev_err(ddata->dev, "register outside module range");
719
720 return -EINVAL;
721 }
722
723 for (j = 0; j < SYSC_MAX_REGS; j++) {
724 if (ddata->offsets[j] < 0)
725 continue;
726
727 if (ddata->offsets[i] == ddata->offsets[j])
728 nr_matches++;
729 }
730 nr_regs++;
731 }
732
Tony Lindgren0eecc632017-10-10 14:23:43 -0700733 if (nr_matches > nr_regs) {
734 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
735 nr_regs, nr_matches);
736
737 return -EINVAL;
738 }
739
740 return 0;
741}
742
743/**
744 * syc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700745 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700746 *
747 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700748 * within the interconnect target module range. For example, SGX has
749 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
750 * has them at offset 0x1200 in the CPSW_WR child. Usually the
751 * the interconnect target module registers are at the beginning of
752 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700753 */
754static int sysc_ioremap(struct sysc *ddata)
755{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700756 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700757
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700758 if (ddata->offsets[SYSC_REVISION] < 0 &&
759 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
760 ddata->offsets[SYSC_SYSSTATUS] < 0) {
761 size = ddata->module_size;
762 } else {
763 size = max3(ddata->offsets[SYSC_REVISION],
764 ddata->offsets[SYSC_SYSCONFIG],
765 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700766
Tony Lindgren4e23be42019-06-10 04:48:05 -0700767 if (size < SZ_1K)
768 size = SZ_1K;
769
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700770 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700771 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700772 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700773
Tony Lindgren0eecc632017-10-10 14:23:43 -0700774 ddata->module_va = devm_ioremap(ddata->dev,
775 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700776 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700777 if (!ddata->module_va)
778 return -EIO;
779
780 return 0;
781}
782
783/**
784 * sysc_map_and_check_registers - ioremap and check device registers
785 * @ddata: device driver data
786 */
787static int sysc_map_and_check_registers(struct sysc *ddata)
788{
789 int error;
790
791 error = sysc_parse_and_check_child_range(ddata);
792 if (error)
793 return error;
794
795 error = sysc_check_children(ddata);
796 if (error)
797 return error;
798
799 error = sysc_parse_registers(ddata);
800 if (error)
801 return error;
802
803 error = sysc_ioremap(ddata);
804 if (error)
805 return error;
806
807 error = sysc_check_registers(ddata);
808 if (error)
809 return error;
810
811 return 0;
812}
813
814/**
815 * sysc_show_rev - read and show interconnect target module revision
816 * @bufp: buffer to print the information to
817 * @ddata: device driver data
818 */
819static int sysc_show_rev(char *bufp, struct sysc *ddata)
820{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800821 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700822
823 if (ddata->offsets[SYSC_REVISION] < 0)
824 return sprintf(bufp, ":NA");
825
Tony Lindgren566a9b052017-12-15 09:41:19 -0800826 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700827
828 return len;
829}
830
831static int sysc_show_reg(struct sysc *ddata,
832 char *bufp, enum sysc_registers reg)
833{
834 if (ddata->offsets[reg] < 0)
835 return sprintf(bufp, ":NA");
836
837 return sprintf(bufp, ":%x", ddata->offsets[reg]);
838}
839
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800840static int sysc_show_name(char *bufp, struct sysc *ddata)
841{
842 if (!ddata->name)
843 return 0;
844
845 return sprintf(bufp, ":%s", ddata->name);
846}
847
Tony Lindgren0eecc632017-10-10 14:23:43 -0700848/**
849 * sysc_show_registers - show information about interconnect target module
850 * @ddata: device driver data
851 */
852static void sysc_show_registers(struct sysc *ddata)
853{
854 char buf[128];
855 char *bufp = buf;
856 int i;
857
858 for (i = 0; i < SYSC_MAX_REGS; i++)
859 bufp += sysc_show_reg(ddata, bufp, i);
860
861 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800862 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700863
864 dev_dbg(ddata->dev, "%llx:%x%s\n",
865 ddata->module_pa, ddata->module_size,
866 buf);
867}
868
Roger Quadrosd59b6052019-04-08 12:52:39 +0300869#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700870#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +0300871
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700872/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300873static int sysc_enable_module(struct device *dev)
874{
875 struct sysc *ddata;
876 const struct sysc_regbits *regbits;
877 u32 reg, idlemodes, best_mode;
878
879 ddata = dev_get_drvdata(dev);
880 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
881 return 0;
882
Roger Quadrosd59b6052019-04-08 12:52:39 +0300883 regbits = ddata->cap->regbits;
884 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
885
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700886 /* Set CLOCKACTIVITY, we only use it for ick */
887 if (regbits->clkact_shift >= 0 &&
888 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT ||
889 ddata->cfg.sysc_val & BIT(regbits->clkact_shift)))
890 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
891
Roger Quadrosd59b6052019-04-08 12:52:39 +0300892 /* Set SIDLE mode */
893 idlemodes = ddata->cfg.sidlemodes;
894 if (!idlemodes || regbits->sidle_shift < 0)
895 goto set_midle;
896
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700897 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
898 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
899 best_mode = SYSC_IDLE_NO;
900 } else {
901 best_mode = fls(ddata->cfg.sidlemodes) - 1;
902 if (best_mode > SYSC_IDLE_MASK) {
903 dev_err(dev, "%s: invalid sidlemode\n", __func__);
904 return -EINVAL;
905 }
Tony Lindgren6e09f492019-05-27 04:51:55 -0700906
907 /* Set WAKEUP */
908 if (regbits->enwkup_shift >= 0 &&
909 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
910 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +0300911 }
912
913 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
914 reg |= best_mode << regbits->sidle_shift;
915 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
916
917set_midle:
918 /* Set MIDLE mode */
919 idlemodes = ddata->cfg.midlemodes;
920 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -0700921 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +0300922
923 best_mode = fls(ddata->cfg.midlemodes) - 1;
924 if (best_mode > SYSC_IDLE_MASK) {
925 dev_err(dev, "%s: invalid midlemode\n", __func__);
926 return -EINVAL;
927 }
928
929 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
930 reg |= best_mode << regbits->midle_shift;
931 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
932
Tony Lindgreneec26552019-05-27 04:51:54 -0700933set_autoidle:
934 /* Autoidle bit must enabled separately if available */
935 if (regbits->autoidle_shift >= 0 &&
936 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
937 reg |= 1 << regbits->autoidle_shift;
938 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
939 }
940
Roger Quadrosd59b6052019-04-08 12:52:39 +0300941 return 0;
942}
943
944static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
945{
946 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
947 *best_mode = SYSC_IDLE_SMART_WKUP;
948 else if (idlemodes & BIT(SYSC_IDLE_SMART))
949 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -0700950 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +0300951 *best_mode = SYSC_IDLE_FORCE;
952 else
953 return -EINVAL;
954
955 return 0;
956}
957
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700958/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300959static int sysc_disable_module(struct device *dev)
960{
961 struct sysc *ddata;
962 const struct sysc_regbits *regbits;
963 u32 reg, idlemodes, best_mode;
964 int ret;
965
966 ddata = dev_get_drvdata(dev);
967 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
968 return 0;
969
Roger Quadrosd59b6052019-04-08 12:52:39 +0300970 regbits = ddata->cap->regbits;
971 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
972
973 /* Set MIDLE mode */
974 idlemodes = ddata->cfg.midlemodes;
975 if (!idlemodes || regbits->midle_shift < 0)
976 goto set_sidle;
977
978 ret = sysc_best_idle_mode(idlemodes, &best_mode);
979 if (ret) {
980 dev_err(dev, "%s: invalid midlemode\n", __func__);
981 return ret;
982 }
983
984 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
985 reg |= best_mode << regbits->midle_shift;
986 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
987
988set_sidle:
989 /* Set SIDLE mode */
990 idlemodes = ddata->cfg.sidlemodes;
991 if (!idlemodes || regbits->sidle_shift < 0)
992 return 0;
993
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700994 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
995 best_mode = SYSC_IDLE_FORCE;
996 } else {
997 ret = sysc_best_idle_mode(idlemodes, &best_mode);
998 if (ret) {
999 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1000 return ret;
1001 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001002 }
1003
1004 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1005 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -07001006 if (regbits->autoidle_shift >= 0 &&
1007 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1008 reg |= 1 << regbits->autoidle_shift;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001009 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
1010
1011 return 0;
1012}
1013
Tony Lindgrenff437282019-03-21 11:00:21 -07001014static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1015 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001016{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001017 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001018 int error;
1019
1020 pdata = dev_get_platdata(ddata->dev);
1021 if (!pdata)
1022 return 0;
1023
1024 if (!pdata->idle_module)
1025 return -ENODEV;
1026
1027 error = pdata->idle_module(dev, &ddata->cookie);
1028 if (error)
1029 dev_err(dev, "%s: could not idle: %i\n",
1030 __func__, error);
1031
Tero Kristo4345f0d2019-08-07 15:46:04 +03001032 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001033
Tony Lindgrenff437282019-03-21 11:00:21 -07001034 return 0;
1035}
1036
1037static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1038 struct sysc *ddata)
1039{
1040 struct ti_sysc_platform_data *pdata;
1041 int error;
1042
Tero Kristo4345f0d2019-08-07 15:46:04 +03001043 reset_control_deassert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001044
Tony Lindgrenff437282019-03-21 11:00:21 -07001045 pdata = dev_get_platdata(ddata->dev);
1046 if (!pdata)
1047 return 0;
1048
1049 if (!pdata->enable_module)
1050 return -ENODEV;
1051
1052 error = pdata->enable_module(dev, &ddata->cookie);
1053 if (error)
1054 dev_err(dev, "%s: could not enable: %i\n",
1055 __func__, error);
1056
1057 return 0;
1058}
1059
1060static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1061{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001062 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001063 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001064
1065 ddata = dev_get_drvdata(dev);
1066
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001067 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001068 return 0;
1069
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001070 sysc_clkdm_deny_idle(ddata);
1071
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001072 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001073 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001074 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001075 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001076 } else {
1077 error = sysc_disable_module(dev);
1078 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001079 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001080 }
1081
Tony Lindgrend8789702019-03-21 11:00:21 -07001082 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001083
Tony Lindgrend8789702019-03-21 11:00:21 -07001084 if (sysc_opt_clks_needed(ddata))
1085 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001086
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001087 ddata->enabled = false;
1088
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001089err_allow_idle:
Tero Kristo4345f0d2019-08-07 15:46:04 +03001090 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001091
Tero Kristob6036312019-08-07 15:46:03 +03001092 sysc_clkdm_allow_idle(ddata);
1093
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001094 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001095}
1096
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001097static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001098{
1099 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001100 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001101
1102 ddata = dev_get_drvdata(dev);
1103
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001104 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001105 return 0;
1106
Tony Lindgren8383e252019-05-27 04:51:56 -07001107
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001108 sysc_clkdm_deny_idle(ddata);
1109
Tero Kristo4345f0d2019-08-07 15:46:04 +03001110 reset_control_deassert(ddata->rsts);
Tero Kristob6036312019-08-07 15:46:03 +03001111
Tony Lindgrend8789702019-03-21 11:00:21 -07001112 if (sysc_opt_clks_needed(ddata)) {
1113 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001114 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001115 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001116 }
1117
Tony Lindgrend8789702019-03-21 11:00:21 -07001118 error = sysc_enable_main_clocks(ddata);
1119 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001120 goto err_opt_clocks;
1121
1122 if (ddata->legacy_mode) {
1123 error = sysc_runtime_resume_legacy(dev, ddata);
1124 if (error)
1125 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001126 } else {
1127 error = sysc_enable_module(dev);
1128 if (error)
1129 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001130 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001131
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001132 ddata->enabled = true;
1133
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001134 sysc_clkdm_allow_idle(ddata);
1135
Tony Lindgrend8789702019-03-21 11:00:21 -07001136 return 0;
1137
1138err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001139 sysc_disable_main_clocks(ddata);
1140err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001141 if (sysc_opt_clks_needed(ddata))
1142 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001143err_allow_idle:
1144 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001145
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001146 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001147}
1148
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001149static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001150{
1151 struct sysc *ddata;
1152
1153 ddata = dev_get_drvdata(dev);
1154
Tony Lindgren40d9f912018-09-24 12:16:54 -07001155 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001156 return 0;
1157
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001158 return pm_runtime_force_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001159}
1160
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001161static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001162{
1163 struct sysc *ddata;
1164
1165 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001166
Tony Lindgren40d9f912018-09-24 12:16:54 -07001167 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001168 return 0;
1169
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001170 return pm_runtime_force_resume(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001171}
1172
Tony Lindgren0eecc632017-10-10 14:23:43 -07001173static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001174 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001175 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1176 sysc_runtime_resume,
1177 NULL)
1178};
1179
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001180/* Module revision register based quirks */
1181struct sysc_revision_quirk {
1182 const char *name;
1183 u32 base;
1184 int rev_offset;
1185 int sysc_offset;
1186 int syss_offset;
1187 u32 revision;
1188 u32 revision_mask;
1189 u32 quirks;
1190};
1191
1192#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1193 optrev_val, optrevmask, optquirkmask) \
1194 { \
1195 .name = (optname), \
1196 .base = (optbase), \
1197 .rev_offset = (optrev), \
1198 .sysc_offset = (optsysc), \
1199 .syss_offset = (optsyss), \
1200 .revision = (optrev_val), \
1201 .revision_mask = (optrevmask), \
1202 .quirks = (optquirkmask), \
1203 }
1204
1205static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1206 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001207 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -07001208 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001209 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
1210 SYSC_QUIRK_LEGACY_IDLE),
1211 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff,
1212 SYSC_QUIRK_LEGACY_IDLE),
1213 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1214 SYSC_QUIRK_LEGACY_IDLE),
1215 SYSC_QUIRK("smartreflex", 0, -1, 0x24, -1, 0x00000000, 0xffffffff,
1216 SYSC_QUIRK_LEGACY_IDLE),
1217 SYSC_QUIRK("smartreflex", 0, -1, 0x38, -1, 0x00000000, 0xffffffff,
1218 SYSC_QUIRK_LEGACY_IDLE),
1219 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001220 0),
Tony Lindgren8cde5d52018-04-16 10:25:15 -07001221 /* Some timers on omap4 and later */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001222 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x50002100, 0xffffffff,
Tony Lindgren072167d2019-01-29 07:53:47 -08001223 0),
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001224 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x4fff1301, 0xffff00ff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001225 0),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001226 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1227 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001228 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001229 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001230 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001231 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001232 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001233 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001234 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001235
Tony Lindgrena54275f2019-03-21 11:00:21 -07001236 /* Quirks that need to be set based on the module address */
1237 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -1, 0x50000800, 0xffffffff,
1238 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1239 SYSC_QUIRK_SWSUP_SIDLE),
1240
Tony Lindgren4e23be42019-06-10 04:48:05 -07001241 /* Quirks that need to be set based on detected module */
1242 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
1243 SYSC_MODULE_QUIRK_HDQ1W),
1244 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
1245 SYSC_MODULE_QUIRK_HDQ1W),
1246 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
1247 SYSC_MODULE_QUIRK_I2C),
1248 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
1249 SYSC_MODULE_QUIRK_I2C),
1250 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
1251 SYSC_MODULE_QUIRK_I2C),
1252 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
1253 SYSC_MODULE_QUIRK_I2C),
1254 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1255 SYSC_MODULE_QUIRK_WDT),
1256
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001257#ifdef DEBUG
Tony Lindgren1ba30692018-09-24 12:17:05 -07001258 SYSC_QUIRK("adc", 0, 0, 0x10, -1, 0x47300001, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001259 SYSC_QUIRK("atl", 0, 0, -1, -1, 0x0a070100, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001260 SYSC_QUIRK("aess", 0, 0, 0x10, -1, 0x40000000, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001261 SYSC_QUIRK("cm", 0, 0, -1, -1, 0x40000301, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001262 SYSC_QUIRK("control", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001263 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001264 0xffff00f0, 0),
Tony Lindgren89bbc6f2019-07-22 03:44:42 -07001265 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0xa3170504, 0xffffffff, 0),
1266 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren13aad512019-03-21 11:00:21 -07001267 SYSC_QUIRK("dmic", 0, 0, 0x10, -1, 0x50010000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001268 SYSC_QUIRK("dwc3", 0, 0, 0x10, -1, 0x500a0200, 0xffffffff, 0),
1269 SYSC_QUIRK("epwmss", 0, 0, 0x4, -1, 0x47400001, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001270 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -1, 0, 0, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001271 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
1272 SYSC_QUIRK("iss", 0, 0, 0x10, -1, 0x40000101, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001273 SYSC_QUIRK("lcdc", 0, 0, 0x54, -1, 0x4f201000, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001274 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44306302, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001275 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44307b02, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001276 SYSC_QUIRK("mcbsp", 0, -1, 0x8c, -1, 0, 0, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001277 SYSC_QUIRK("mcspi", 0, 0, 0x10, -1, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001278 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001279 SYSC_QUIRK("mailbox", 0, 0, 0x10, -1, 0x00000400, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001280 SYSC_QUIRK("m3", 0, 0, -1, -1, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001281 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001282 SYSC_QUIRK("ocp2scp", 0, 0, -1, -1, 0x50060007, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001283 SYSC_QUIRK("padconf", 0, 0, 0x10, -1, 0x4fff0800, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001284 SYSC_QUIRK("padconf", 0, 0, -1, -1, 0x40001100, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001285 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000100, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001286 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x00004102, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001287 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000400, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001288 SYSC_QUIRK("scm", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001289 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4e8b0100, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001290 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4f000100, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001291 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001292 SYSC_QUIRK("scrm", 0, 0, -1, -1, 0x00000010, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001293 SYSC_QUIRK("sdio", 0, 0, 0x10, -1, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001294 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001295 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001296 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40000902, 0xffffffff, 0),
1297 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40002903, 0xffffffff, 0),
1298 SYSC_QUIRK("spinlock", 0, 0, 0x10, -1, 0x50020000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001299 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -1, 0x00000020, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001300 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -1, 0x4eb01908, 0xffff00f0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001301 SYSC_QUIRK("timer32k", 0, 0, 0x4, -1, 0x00000060, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001302 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001303 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001304 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001305 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -1, 0x50700101, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001306 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1307 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001308 SYSC_QUIRK("vfpe", 0, 0, 0x104, -1, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001309#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001310};
1311
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001312/*
1313 * Early quirks based on module base and register offsets only that are
1314 * needed before the module revision can be read
1315 */
1316static void sysc_init_early_quirks(struct sysc *ddata)
1317{
1318 const struct sysc_revision_quirk *q;
1319 int i;
1320
1321 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1322 q = &sysc_revision_quirks[i];
1323
1324 if (!q->base)
1325 continue;
1326
1327 if (q->base != ddata->module_pa)
1328 continue;
1329
1330 if (q->rev_offset >= 0 &&
1331 q->rev_offset != ddata->offsets[SYSC_REVISION])
1332 continue;
1333
1334 if (q->sysc_offset >= 0 &&
1335 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1336 continue;
1337
1338 if (q->syss_offset >= 0 &&
1339 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1340 continue;
1341
1342 ddata->name = q->name;
1343 ddata->cfg.quirks |= q->quirks;
1344 }
1345}
1346
1347/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001348static void sysc_init_revision_quirks(struct sysc *ddata)
1349{
1350 const struct sysc_revision_quirk *q;
1351 int i;
1352
1353 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1354 q = &sysc_revision_quirks[i];
1355
1356 if (q->base && q->base != ddata->module_pa)
1357 continue;
1358
1359 if (q->rev_offset >= 0 &&
1360 q->rev_offset != ddata->offsets[SYSC_REVISION])
1361 continue;
1362
1363 if (q->sysc_offset >= 0 &&
1364 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1365 continue;
1366
1367 if (q->syss_offset >= 0 &&
1368 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1369 continue;
1370
1371 if (q->revision == ddata->revision ||
1372 (q->revision & q->revision_mask) ==
1373 (ddata->revision & q->revision_mask)) {
1374 ddata->name = q->name;
1375 ddata->cfg.quirks |= q->quirks;
1376 }
1377 }
1378}
1379
Tony Lindgren4e23be42019-06-10 04:48:05 -07001380/* 1-wire needs module's internal clocks enabled for reset */
1381static void sysc_clk_enable_quirk_hdq1w(struct sysc *ddata)
1382{
1383 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1384 u16 val;
1385
1386 val = sysc_read(ddata, offset);
1387 val |= BIT(5);
1388 sysc_write(ddata, offset, val);
1389}
1390
1391/* I2C needs extra enable bit toggling for reset */
1392static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1393{
1394 int offset;
1395 u16 val;
1396
1397 /* I2C_CON, omap2/3 is different from omap4 and later */
1398 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1399 offset = 0x24;
1400 else
1401 offset = 0xa4;
1402
1403 /* I2C_EN */
1404 val = sysc_read(ddata, offset);
1405 if (enable)
1406 val |= BIT(15);
1407 else
1408 val &= ~BIT(15);
1409 sysc_write(ddata, offset, val);
1410}
1411
1412static void sysc_clk_enable_quirk_i2c(struct sysc *ddata)
1413{
1414 sysc_clk_quirk_i2c(ddata, true);
1415}
1416
1417static void sysc_clk_disable_quirk_i2c(struct sysc *ddata)
1418{
1419 sysc_clk_quirk_i2c(ddata, false);
1420}
1421
1422/* Watchdog timer needs a disable sequence after reset */
1423static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1424{
1425 int wps, spr, error;
1426 u32 val;
1427
1428 wps = 0x34;
1429 spr = 0x48;
1430
1431 sysc_write(ddata, spr, 0xaaaa);
1432 error = readl_poll_timeout(ddata->module_va + wps, val,
1433 !(val & 0x10), 100,
1434 MAX_MODULE_SOFTRESET_WAIT);
1435 if (error)
1436 dev_warn(ddata->dev, "wdt disable spr failed\n");
1437
1438 sysc_write(ddata, wps, 0x5555);
1439 error = readl_poll_timeout(ddata->module_va + wps, val,
1440 !(val & 0x10), 100,
1441 MAX_MODULE_SOFTRESET_WAIT);
1442 if (error)
1443 dev_warn(ddata->dev, "wdt disable wps failed\n");
1444}
1445
1446static void sysc_init_module_quirks(struct sysc *ddata)
1447{
1448 if (ddata->legacy_mode || !ddata->name)
1449 return;
1450
1451 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
1452 ddata->clk_enable_quirk = sysc_clk_enable_quirk_hdq1w;
1453
1454 return;
1455 }
1456
1457 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
1458 ddata->clk_enable_quirk = sysc_clk_enable_quirk_i2c;
1459 ddata->clk_disable_quirk = sysc_clk_disable_quirk_i2c;
1460
1461 return;
1462 }
1463
1464 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT)
1465 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
1466}
1467
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001468static int sysc_clockdomain_init(struct sysc *ddata)
1469{
1470 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1471 struct clk *fck = NULL, *ick = NULL;
1472 int error;
1473
1474 if (!pdata || !pdata->init_clockdomain)
1475 return 0;
1476
1477 switch (ddata->nr_clocks) {
1478 case 2:
1479 ick = ddata->clocks[SYSC_ICK];
1480 /* fallthrough */
1481 case 1:
1482 fck = ddata->clocks[SYSC_FCK];
1483 break;
1484 case 0:
1485 return 0;
1486 }
1487
1488 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
1489 if (!error || error == -ENODEV)
1490 return 0;
1491
1492 return error;
1493}
1494
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001495/*
1496 * Note that pdata->init_module() typically does a reset first. After
1497 * pdata->init_module() is done, PM runtime can be used for the interconnect
1498 * target module.
1499 */
1500static int sysc_legacy_init(struct sysc *ddata)
1501{
1502 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1503 int error;
1504
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001505 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001506 return 0;
1507
1508 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
1509 if (error == -EEXIST)
1510 error = 0;
1511
1512 return error;
1513}
1514
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001515/**
1516 * sysc_rstctrl_reset_deassert - deassert rstctrl reset
1517 * @ddata: device driver data
1518 * @reset: reset before deassert
1519 *
1520 * A module can have both OCP softreset control and external rstctrl.
1521 * If more complicated rstctrl resets are needed, please handle these
1522 * directly from the child device driver and map only the module reset
1523 * for the parent interconnect target module device.
1524 *
1525 * Automatic reset of the module on init can be skipped with the
1526 * "ti,no-reset-on-init" device tree property.
1527 */
1528static int sysc_rstctrl_reset_deassert(struct sysc *ddata, bool reset)
1529{
Tero Kristobb88b862019-08-07 15:46:05 +03001530 int error;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001531
1532 if (!ddata->rsts)
1533 return 0;
1534
1535 if (reset) {
1536 error = reset_control_assert(ddata->rsts);
1537 if (error)
1538 return error;
1539 }
1540
Tero Kristobb88b862019-08-07 15:46:05 +03001541 reset_control_deassert(ddata->rsts);
1542
1543 return 0;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001544}
1545
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001546/*
1547 * Note that the caller must ensure the interconnect target module is enabled
1548 * before calling reset. Otherwise reset will not complete.
1549 */
Faiz Abbas596e7952018-07-09 22:18:39 +05301550static int sysc_reset(struct sysc *ddata)
1551{
YueHaibingc8a738f2019-06-28 12:10:54 +08001552 int sysc_offset, syss_offset, sysc_val, rstval, error = 0;
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001553 u32 sysc_mask, syss_done;
Faiz Abbas596e7952018-07-09 22:18:39 +05301554
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001555 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
1556 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001557
1558 if (ddata->legacy_mode || sysc_offset < 0 ||
1559 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05301560 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
1561 return 0;
1562
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001563 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05301564
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001565 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
1566 syss_done = 0;
1567 else
1568 syss_done = ddata->cfg.syss_mask;
1569
Tony Lindgren4e23be42019-06-10 04:48:05 -07001570 if (ddata->clk_disable_quirk)
1571 ddata->clk_disable_quirk(ddata);
1572
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001573 sysc_val = sysc_read_sysconfig(ddata);
1574 sysc_val |= sysc_mask;
1575 sysc_write(ddata, sysc_offset, sysc_val);
Faiz Abbas596e7952018-07-09 22:18:39 +05301576
Tony Lindgren4e23be42019-06-10 04:48:05 -07001577 if (ddata->clk_enable_quirk)
1578 ddata->clk_enable_quirk(ddata);
1579
Faiz Abbas596e7952018-07-09 22:18:39 +05301580 /* Poll on reset status */
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001581 if (syss_offset >= 0) {
1582 error = readx_poll_timeout(sysc_read_sysstatus, ddata, rstval,
1583 (rstval & ddata->cfg.syss_mask) ==
1584 syss_done,
1585 100, MAX_MODULE_SOFTRESET_WAIT);
Faiz Abbas596e7952018-07-09 22:18:39 +05301586
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001587 } else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS) {
1588 error = readx_poll_timeout(sysc_read_sysconfig, ddata, rstval,
1589 !(rstval & sysc_mask),
1590 100, MAX_MODULE_SOFTRESET_WAIT);
1591 }
1592
Tony Lindgren4e23be42019-06-10 04:48:05 -07001593 if (ddata->reset_done_quirk)
1594 ddata->reset_done_quirk(ddata);
1595
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001596 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05301597}
1598
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001599/*
1600 * At this point the module is configured enough to read the revision but
1601 * module may not be completely configured yet to use PM runtime. Enable
1602 * all clocks directly during init to configure the quirks needed for PM
1603 * runtime based on the revision register.
1604 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08001605static int sysc_init_module(struct sysc *ddata)
1606{
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001607 int error = 0;
1608 bool manage_clocks = true;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001609
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001610 error = sysc_rstctrl_reset_deassert(ddata, false);
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001611 if (error)
1612 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001613
Tony Lindgren386cb762019-03-22 07:49:30 -07001614 if (ddata->cfg.quirks &
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001615 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))
1616 manage_clocks = false;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001617
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001618 error = sysc_clockdomain_init(ddata);
1619 if (error)
1620 return error;
1621
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001622 if (manage_clocks) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001623 sysc_clkdm_deny_idle(ddata);
1624
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001625 error = sysc_enable_opt_clocks(ddata);
1626 if (error)
1627 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001628
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001629 error = sysc_enable_main_clocks(ddata);
1630 if (error)
1631 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05301632 }
1633
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001634 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
1635 error = sysc_rstctrl_reset_deassert(ddata, true);
1636 if (error)
1637 goto err_main_clocks;
1638 }
1639
Tony Lindgren566a9b052017-12-15 09:41:19 -08001640 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001641 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001642 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001643
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001644 if (ddata->legacy_mode) {
1645 error = sysc_legacy_init(ddata);
1646 if (error)
1647 goto err_main_clocks;
1648 }
1649
1650 if (!ddata->legacy_mode && manage_clocks) {
1651 error = sysc_enable_module(ddata->dev);
1652 if (error)
1653 goto err_main_clocks;
1654 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001655
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001656 error = sysc_reset(ddata);
1657 if (error)
1658 dev_err(ddata->dev, "Reset failed with %d\n", error);
1659
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001660 if (!ddata->legacy_mode && manage_clocks)
1661 sysc_disable_module(ddata->dev);
1662
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001663err_main_clocks:
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001664 if (manage_clocks)
1665 sysc_disable_main_clocks(ddata);
1666err_opt_clocks:
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001667 if (manage_clocks) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001668 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001669 sysc_clkdm_allow_idle(ddata);
1670 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001671
1672 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001673}
1674
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001675static int sysc_init_sysc_mask(struct sysc *ddata)
1676{
1677 struct device_node *np = ddata->dev->of_node;
1678 int error;
1679 u32 val;
1680
1681 error = of_property_read_u32(np, "ti,sysc-mask", &val);
1682 if (error)
1683 return 0;
1684
Tony Lindgrene212abd2019-07-22 03:44:52 -07001685 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001686
1687 return 0;
1688}
1689
1690static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
1691 const char *name)
1692{
1693 struct device_node *np = ddata->dev->of_node;
1694 struct property *prop;
1695 const __be32 *p;
1696 u32 val;
1697
1698 of_property_for_each_u32(np, name, prop, p, val) {
1699 if (val >= SYSC_NR_IDLEMODES) {
1700 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
1701 return -EINVAL;
1702 }
1703 *idlemodes |= (1 << val);
1704 }
1705
1706 return 0;
1707}
1708
1709static int sysc_init_idlemodes(struct sysc *ddata)
1710{
1711 int error;
1712
1713 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
1714 "ti,sysc-midle");
1715 if (error)
1716 return error;
1717
1718 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
1719 "ti,sysc-sidle");
1720 if (error)
1721 return error;
1722
1723 return 0;
1724}
1725
1726/*
1727 * Only some devices on omap4 and later have SYSCONFIG reset done
1728 * bit. We can detect this if there is no SYSSTATUS at all, or the
1729 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
1730 * have multiple bits for the child devices like OHCI and EHCI.
1731 * Depends on SYSC being parsed first.
1732 */
1733static int sysc_init_syss_mask(struct sysc *ddata)
1734{
1735 struct device_node *np = ddata->dev->of_node;
1736 int error;
1737 u32 val;
1738
1739 error = of_property_read_u32(np, "ti,syss-mask", &val);
1740 if (error) {
1741 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
1742 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
1743 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1744 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1745
1746 return 0;
1747 }
1748
1749 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1750 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1751
1752 ddata->cfg.syss_mask = val;
1753
1754 return 0;
1755}
1756
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001757/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001758 * Many child device drivers need to have fck and opt clocks available
1759 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001760 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001761static int sysc_child_add_named_clock(struct sysc *ddata,
1762 struct device *child,
1763 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001764{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001765 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001766 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001767 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001768
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001769 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001770 return 0;
1771
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001772 clk = clk_get(child, name);
1773 if (!IS_ERR(clk)) {
1774 clk_put(clk);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001775
1776 return -EEXIST;
1777 }
1778
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001779 clk = clk_get(ddata->dev, name);
1780 if (IS_ERR(clk))
1781 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001782
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001783 l = clkdev_create(clk, name, dev_name(child));
1784 if (!l)
1785 error = -ENOMEM;
1786
1787 clk_put(clk);
1788
1789 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001790}
1791
Tony Lindgren09dfe582018-04-16 10:25:52 -07001792static int sysc_child_add_clocks(struct sysc *ddata,
1793 struct device *child)
1794{
1795 int i, error;
1796
1797 for (i = 0; i < ddata->nr_clocks; i++) {
1798 error = sysc_child_add_named_clock(ddata,
1799 child,
1800 ddata->clock_roles[i]);
1801 if (error && error != -EEXIST) {
1802 dev_err(ddata->dev, "could not add child clock %s: %i\n",
1803 ddata->clock_roles[i], error);
1804
1805 return error;
1806 }
1807 }
1808
1809 return 0;
1810}
1811
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001812static struct device_type sysc_device_type = {
1813};
1814
1815static struct sysc *sysc_child_to_parent(struct device *dev)
1816{
1817 struct device *parent = dev->parent;
1818
1819 if (!parent || parent->type != &sysc_device_type)
1820 return NULL;
1821
1822 return dev_get_drvdata(parent);
1823}
1824
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001825static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
1826{
1827 struct sysc *ddata;
1828 int error;
1829
1830 ddata = sysc_child_to_parent(dev);
1831
1832 error = pm_generic_runtime_suspend(dev);
1833 if (error)
1834 return error;
1835
1836 if (!ddata->enabled)
1837 return 0;
1838
1839 return sysc_runtime_suspend(ddata->dev);
1840}
1841
1842static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
1843{
1844 struct sysc *ddata;
1845 int error;
1846
1847 ddata = sysc_child_to_parent(dev);
1848
1849 if (!ddata->enabled) {
1850 error = sysc_runtime_resume(ddata->dev);
1851 if (error < 0)
1852 dev_err(ddata->dev,
1853 "%s error: %i\n", __func__, error);
1854 }
1855
1856 return pm_generic_runtime_resume(dev);
1857}
1858
1859#ifdef CONFIG_PM_SLEEP
1860static int sysc_child_suspend_noirq(struct device *dev)
1861{
1862 struct sysc *ddata;
1863 int error;
1864
1865 ddata = sysc_child_to_parent(dev);
1866
Tony Lindgrenef55f822018-04-16 10:27:15 -07001867 dev_dbg(ddata->dev, "%s %s\n", __func__,
1868 ddata->name ? ddata->name : "");
1869
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001870 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001871 if (error) {
1872 dev_err(dev, "%s error at %i: %i\n",
1873 __func__, __LINE__, error);
1874
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001875 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001876 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001877
1878 if (!pm_runtime_status_suspended(dev)) {
1879 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001880 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07001881 dev_dbg(dev, "%s busy at %i: %i\n",
1882 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001883
Tony Lindgren4f3530f2018-08-08 01:07:06 -07001884 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001885 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001886
1887 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001888 if (error) {
1889 dev_err(dev, "%s error at %i: %i\n",
1890 __func__, __LINE__, error);
1891
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001892 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001893 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001894
1895 ddata->child_needs_resume = true;
1896 }
1897
1898 return 0;
1899}
1900
1901static int sysc_child_resume_noirq(struct device *dev)
1902{
1903 struct sysc *ddata;
1904 int error;
1905
1906 ddata = sysc_child_to_parent(dev);
1907
Tony Lindgrenef55f822018-04-16 10:27:15 -07001908 dev_dbg(ddata->dev, "%s %s\n", __func__,
1909 ddata->name ? ddata->name : "");
1910
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001911 if (ddata->child_needs_resume) {
1912 ddata->child_needs_resume = false;
1913
1914 error = sysc_runtime_resume(ddata->dev);
1915 if (error)
1916 dev_err(ddata->dev,
1917 "%s runtime resume error: %i\n",
1918 __func__, error);
1919
1920 error = pm_generic_runtime_resume(dev);
1921 if (error)
1922 dev_err(ddata->dev,
1923 "%s generic runtime resume: %i\n",
1924 __func__, error);
1925 }
1926
1927 return pm_generic_resume_noirq(dev);
1928}
1929#endif
1930
Tony Lindgrenb7182b42019-03-21 11:00:21 -07001931static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001932 .ops = {
1933 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
1934 sysc_child_runtime_resume,
1935 NULL)
1936 USE_PLATFORM_PM_SLEEP_OPS
1937 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
1938 sysc_child_resume_noirq)
1939 }
1940};
1941
1942/**
1943 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
1944 * @ddata: device driver data
1945 * @child: child device driver
1946 *
1947 * Allow idle for child devices as done with _od_runtime_suspend().
1948 * Otherwise many child devices will not idle because of the permanent
1949 * parent usecount set in pm_runtime_irq_safe().
1950 *
1951 * Note that the long term solution is to just modify the child device
1952 * drivers to not set pm_runtime_irq_safe() and then this can be just
1953 * dropped.
1954 */
1955static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
1956{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001957 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
1958 dev_pm_domain_set(child, &sysc_child_pm_domain);
1959}
1960
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001961static int sysc_notifier_call(struct notifier_block *nb,
1962 unsigned long event, void *device)
1963{
1964 struct device *dev = device;
1965 struct sysc *ddata;
1966 int error;
1967
1968 ddata = sysc_child_to_parent(dev);
1969 if (!ddata)
1970 return NOTIFY_DONE;
1971
1972 switch (event) {
1973 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07001974 error = sysc_child_add_clocks(ddata, dev);
1975 if (error)
1976 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001977 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001978 break;
1979 default:
1980 break;
1981 }
1982
1983 return NOTIFY_DONE;
1984}
1985
1986static struct notifier_block sysc_nb = {
1987 .notifier_call = sysc_notifier_call,
1988};
1989
Tony Lindgren566a9b052017-12-15 09:41:19 -08001990/* Device tree configured quirks */
1991struct sysc_dts_quirk {
1992 const char *name;
1993 u32 mask;
1994};
1995
1996static const struct sysc_dts_quirk sysc_dts_quirks[] = {
1997 { .name = "ti,no-idle-on-init",
1998 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
1999 { .name = "ti,no-reset-on-init",
2000 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002001 { .name = "ti,no-idle",
2002 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002003};
2004
Tony Lindgren4014c082018-12-10 14:11:26 -08002005static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2006 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002007{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002008 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002009 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002010
2011 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002012 const char *name = sysc_dts_quirks[i].name;
2013
2014 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002015 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002016 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002017
2018 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002019 if (is_child) {
2020 dev_warn(ddata->dev,
2021 "dts flag should be at module level for %s\n",
2022 name);
2023 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002024 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002025}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002026
Tony Lindgren4014c082018-12-10 14:11:26 -08002027static int sysc_init_dts_quirks(struct sysc *ddata)
2028{
2029 struct device_node *np = ddata->dev->of_node;
2030 int error;
2031 u32 val;
2032
2033 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2034
2035 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002036 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2037 if (!error) {
2038 if (val > 255) {
2039 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2040 val);
2041 }
2042
2043 ddata->cfg.srst_udelay = (u8)val;
2044 }
2045
2046 return 0;
2047}
2048
Tony Lindgren0eecc632017-10-10 14:23:43 -07002049static void sysc_unprepare(struct sysc *ddata)
2050{
2051 int i;
2052
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002053 if (!ddata->clocks)
2054 return;
2055
Tony Lindgren0eecc632017-10-10 14:23:43 -07002056 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2057 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2058 clk_unprepare(ddata->clocks[i]);
2059 }
2060}
2061
Tony Lindgren70a65242017-12-15 09:41:09 -08002062/*
2063 * Common sysc register bits found on omap2, also known as type1
2064 */
2065static const struct sysc_regbits sysc_regbits_omap2 = {
2066 .dmadisable_shift = -ENODEV,
2067 .midle_shift = 12,
2068 .sidle_shift = 3,
2069 .clkact_shift = 8,
2070 .emufree_shift = 5,
2071 .enwkup_shift = 2,
2072 .srst_shift = 1,
2073 .autoidle_shift = 0,
2074};
2075
2076static const struct sysc_capabilities sysc_omap2 = {
2077 .type = TI_SYSC_OMAP2,
2078 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2079 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2080 SYSC_OMAP2_AUTOIDLE,
2081 .regbits = &sysc_regbits_omap2,
2082};
2083
2084/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2085static const struct sysc_capabilities sysc_omap2_timer = {
2086 .type = TI_SYSC_OMAP2_TIMER,
2087 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2088 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2089 SYSC_OMAP2_AUTOIDLE,
2090 .regbits = &sysc_regbits_omap2,
2091 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2092};
2093
2094/*
2095 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2096 * with different sidle position
2097 */
2098static const struct sysc_regbits sysc_regbits_omap3_sham = {
2099 .dmadisable_shift = -ENODEV,
2100 .midle_shift = -ENODEV,
2101 .sidle_shift = 4,
2102 .clkact_shift = -ENODEV,
2103 .enwkup_shift = -ENODEV,
2104 .srst_shift = 1,
2105 .autoidle_shift = 0,
2106 .emufree_shift = -ENODEV,
2107};
2108
2109static const struct sysc_capabilities sysc_omap3_sham = {
2110 .type = TI_SYSC_OMAP3_SHAM,
2111 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2112 .regbits = &sysc_regbits_omap3_sham,
2113};
2114
2115/*
2116 * AES register bits found on omap3 and later, a variant of
2117 * sysc_regbits_omap2 with different sidle position
2118 */
2119static const struct sysc_regbits sysc_regbits_omap3_aes = {
2120 .dmadisable_shift = -ENODEV,
2121 .midle_shift = -ENODEV,
2122 .sidle_shift = 6,
2123 .clkact_shift = -ENODEV,
2124 .enwkup_shift = -ENODEV,
2125 .srst_shift = 1,
2126 .autoidle_shift = 0,
2127 .emufree_shift = -ENODEV,
2128};
2129
2130static const struct sysc_capabilities sysc_omap3_aes = {
2131 .type = TI_SYSC_OMAP3_AES,
2132 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2133 .regbits = &sysc_regbits_omap3_aes,
2134};
2135
2136/*
2137 * Common sysc register bits found on omap4, also known as type2
2138 */
2139static const struct sysc_regbits sysc_regbits_omap4 = {
2140 .dmadisable_shift = 16,
2141 .midle_shift = 4,
2142 .sidle_shift = 2,
2143 .clkact_shift = -ENODEV,
2144 .enwkup_shift = -ENODEV,
2145 .emufree_shift = 1,
2146 .srst_shift = 0,
2147 .autoidle_shift = -ENODEV,
2148};
2149
2150static const struct sysc_capabilities sysc_omap4 = {
2151 .type = TI_SYSC_OMAP4,
2152 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2153 SYSC_OMAP4_SOFTRESET,
2154 .regbits = &sysc_regbits_omap4,
2155};
2156
2157static const struct sysc_capabilities sysc_omap4_timer = {
2158 .type = TI_SYSC_OMAP4_TIMER,
2159 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2160 SYSC_OMAP4_SOFTRESET,
2161 .regbits = &sysc_regbits_omap4,
2162};
2163
2164/*
2165 * Common sysc register bits found on omap4, also known as type3
2166 */
2167static const struct sysc_regbits sysc_regbits_omap4_simple = {
2168 .dmadisable_shift = -ENODEV,
2169 .midle_shift = 2,
2170 .sidle_shift = 0,
2171 .clkact_shift = -ENODEV,
2172 .enwkup_shift = -ENODEV,
2173 .srst_shift = -ENODEV,
2174 .emufree_shift = -ENODEV,
2175 .autoidle_shift = -ENODEV,
2176};
2177
2178static const struct sysc_capabilities sysc_omap4_simple = {
2179 .type = TI_SYSC_OMAP4_SIMPLE,
2180 .regbits = &sysc_regbits_omap4_simple,
2181};
2182
2183/*
2184 * SmartReflex sysc found on omap34xx
2185 */
2186static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2187 .dmadisable_shift = -ENODEV,
2188 .midle_shift = -ENODEV,
2189 .sidle_shift = -ENODEV,
2190 .clkact_shift = 20,
2191 .enwkup_shift = -ENODEV,
2192 .srst_shift = -ENODEV,
2193 .emufree_shift = -ENODEV,
2194 .autoidle_shift = -ENODEV,
2195};
2196
2197static const struct sysc_capabilities sysc_34xx_sr = {
2198 .type = TI_SYSC_OMAP34XX_SR,
2199 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2200 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002201 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2202 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002203};
2204
2205/*
2206 * SmartReflex sysc found on omap36xx and later
2207 */
2208static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2209 .dmadisable_shift = -ENODEV,
2210 .midle_shift = -ENODEV,
2211 .sidle_shift = 24,
2212 .clkact_shift = -ENODEV,
2213 .enwkup_shift = 26,
2214 .srst_shift = -ENODEV,
2215 .emufree_shift = -ENODEV,
2216 .autoidle_shift = -ENODEV,
2217};
2218
2219static const struct sysc_capabilities sysc_36xx_sr = {
2220 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002221 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002222 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002223 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002224};
2225
2226static const struct sysc_capabilities sysc_omap4_sr = {
2227 .type = TI_SYSC_OMAP4_SR,
2228 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002229 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002230};
2231
2232/*
2233 * McASP register bits found on omap4 and later
2234 */
2235static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2236 .dmadisable_shift = -ENODEV,
2237 .midle_shift = -ENODEV,
2238 .sidle_shift = 0,
2239 .clkact_shift = -ENODEV,
2240 .enwkup_shift = -ENODEV,
2241 .srst_shift = -ENODEV,
2242 .emufree_shift = -ENODEV,
2243 .autoidle_shift = -ENODEV,
2244};
2245
2246static const struct sysc_capabilities sysc_omap4_mcasp = {
2247 .type = TI_SYSC_OMAP4_MCASP,
2248 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002249 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2250};
2251
2252/*
2253 * McASP found on dra7 and later
2254 */
2255static const struct sysc_capabilities sysc_dra7_mcasp = {
2256 .type = TI_SYSC_OMAP4_SIMPLE,
2257 .regbits = &sysc_regbits_omap4_simple,
2258 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002259};
2260
2261/*
2262 * FS USB host found on omap4 and later
2263 */
2264static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2265 .dmadisable_shift = -ENODEV,
2266 .midle_shift = -ENODEV,
2267 .sidle_shift = 24,
2268 .clkact_shift = -ENODEV,
2269 .enwkup_shift = 26,
2270 .srst_shift = -ENODEV,
2271 .emufree_shift = -ENODEV,
2272 .autoidle_shift = -ENODEV,
2273};
2274
2275static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2276 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2277 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2278 .regbits = &sysc_regbits_omap4_usb_host_fs,
2279};
2280
Faiz Abbas7f35e632018-07-09 22:18:38 +05302281static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2282 .dmadisable_shift = -ENODEV,
2283 .midle_shift = -ENODEV,
2284 .sidle_shift = -ENODEV,
2285 .clkact_shift = -ENODEV,
2286 .enwkup_shift = 4,
2287 .srst_shift = 0,
2288 .emufree_shift = -ENODEV,
2289 .autoidle_shift = -ENODEV,
2290};
2291
2292static const struct sysc_capabilities sysc_dra7_mcan = {
2293 .type = TI_SYSC_DRA7_MCAN,
2294 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2295 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002296 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302297};
2298
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002299static int sysc_init_pdata(struct sysc *ddata)
2300{
2301 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002302 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002303
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002304 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002305 return 0;
2306
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002307 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2308 if (!mdata)
2309 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002310
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002311 if (ddata->legacy_mode) {
2312 mdata->name = ddata->legacy_mode;
2313 mdata->module_pa = ddata->module_pa;
2314 mdata->module_size = ddata->module_size;
2315 mdata->offsets = ddata->offsets;
2316 mdata->nr_offsets = SYSC_MAX_REGS;
2317 mdata->cap = ddata->cap;
2318 mdata->cfg = &ddata->cfg;
2319 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002320
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002321 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002322
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002323 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002324}
2325
Tony Lindgren70a65242017-12-15 09:41:09 -08002326static int sysc_init_match(struct sysc *ddata)
2327{
2328 const struct sysc_capabilities *cap;
2329
2330 cap = of_device_get_match_data(ddata->dev);
2331 if (!cap)
2332 return -EINVAL;
2333
2334 ddata->cap = cap;
2335 if (ddata->cap)
2336 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2337
2338 return 0;
2339}
2340
Tony Lindgren76f0f772018-02-23 08:28:45 -08002341static void ti_sysc_idle(struct work_struct *work)
2342{
2343 struct sysc *ddata;
2344
2345 ddata = container_of(work, struct sysc, idle_work.work);
2346
2347 if (pm_runtime_active(ddata->dev))
2348 pm_runtime_put_sync(ddata->dev);
2349}
2350
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002351static const struct of_device_id sysc_match_table[] = {
2352 { .compatible = "simple-bus", },
2353 { /* sentinel */ },
2354};
2355
Tony Lindgren0eecc632017-10-10 14:23:43 -07002356static int sysc_probe(struct platform_device *pdev)
2357{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002358 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002359 struct sysc *ddata;
2360 int error;
2361
2362 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
2363 if (!ddata)
2364 return -ENOMEM;
2365
2366 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002367 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002368
Tony Lindgren70a65242017-12-15 09:41:09 -08002369 error = sysc_init_match(ddata);
2370 if (error)
2371 return error;
2372
Tony Lindgren566a9b052017-12-15 09:41:19 -08002373 error = sysc_init_dts_quirks(ddata);
2374 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002375 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002376
Tony Lindgren0eecc632017-10-10 14:23:43 -07002377 error = sysc_map_and_check_registers(ddata);
2378 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002379 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07002380
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002381 error = sysc_init_sysc_mask(ddata);
2382 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002383 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002384
2385 error = sysc_init_idlemodes(ddata);
2386 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002387 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002388
2389 error = sysc_init_syss_mask(ddata);
2390 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002391 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002392
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002393 error = sysc_init_pdata(ddata);
2394 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002395 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002396
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07002397 sysc_init_early_quirks(ddata);
2398
2399 error = sysc_get_clocks(ddata);
2400 if (error)
2401 return error;
2402
Tony Lindgren50622362018-04-16 10:20:27 -07002403 error = sysc_init_resets(ddata);
2404 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002405 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002406
2407 error = sysc_init_module(ddata);
2408 if (error)
2409 goto unprepare;
2410
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002411 pm_runtime_enable(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002412 error = pm_runtime_get_sync(ddata->dev);
2413 if (error < 0) {
2414 pm_runtime_put_noidle(ddata->dev);
2415 pm_runtime_disable(ddata->dev);
2416 goto unprepare;
2417 }
2418
Tero Kristobb88b862019-08-07 15:46:05 +03002419 /* Balance reset counts */
2420 if (ddata->rsts)
2421 reset_control_assert(ddata->rsts);
2422
Tony Lindgren0eecc632017-10-10 14:23:43 -07002423 sysc_show_registers(ddata);
2424
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002425 ddata->dev->type = &sysc_device_type;
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002426 error = of_platform_populate(ddata->dev->of_node, sysc_match_table,
2427 pdata ? pdata->auxdata : NULL,
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002428 ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002429 if (error)
2430 goto err;
2431
Tony Lindgren76f0f772018-02-23 08:28:45 -08002432 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
2433
2434 /* At least earlycon won't survive without deferred idle */
2435 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE_ON_INIT |
2436 SYSC_QUIRK_NO_RESET_ON_INIT)) {
2437 schedule_delayed_work(&ddata->idle_work, 3000);
2438 } else {
2439 pm_runtime_put(&pdev->dev);
2440 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07002441
2442 return 0;
2443
2444err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07002445 pm_runtime_put_sync(&pdev->dev);
2446 pm_runtime_disable(&pdev->dev);
2447unprepare:
2448 sysc_unprepare(ddata);
2449
2450 return error;
2451}
2452
Tony Lindgren684be5a2017-10-13 10:48:40 -07002453static int sysc_remove(struct platform_device *pdev)
2454{
2455 struct sysc *ddata = platform_get_drvdata(pdev);
2456 int error;
2457
Tony Lindgren76f0f772018-02-23 08:28:45 -08002458 cancel_delayed_work_sync(&ddata->idle_work);
2459
Tony Lindgren684be5a2017-10-13 10:48:40 -07002460 error = pm_runtime_get_sync(ddata->dev);
2461 if (error < 0) {
2462 pm_runtime_put_noidle(ddata->dev);
2463 pm_runtime_disable(ddata->dev);
2464 goto unprepare;
2465 }
2466
2467 of_platform_depopulate(&pdev->dev);
2468
Tony Lindgren684be5a2017-10-13 10:48:40 -07002469 pm_runtime_put_sync(&pdev->dev);
2470 pm_runtime_disable(&pdev->dev);
Tony Lindgren50622362018-04-16 10:20:27 -07002471 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07002472
2473unprepare:
2474 sysc_unprepare(ddata);
2475
2476 return 0;
2477}
2478
Tony Lindgren0eecc632017-10-10 14:23:43 -07002479static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08002480 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
2481 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
2482 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
2483 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
2484 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
2485 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
2486 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
2487 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
2488 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
2489 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
2490 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08002491 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08002492 { .compatible = "ti,sysc-usb-host-fs",
2493 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05302494 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07002495 { },
2496};
2497MODULE_DEVICE_TABLE(of, sysc_match);
2498
2499static struct platform_driver sysc_driver = {
2500 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07002501 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07002502 .driver = {
2503 .name = "ti-sysc",
2504 .of_match_table = sysc_match,
2505 .pm = &sysc_pm_ops,
2506 },
2507};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002508
2509static int __init sysc_init(void)
2510{
2511 bus_register_notifier(&platform_bus_type, &sysc_nb);
2512
2513 return platform_driver_register(&sysc_driver);
2514}
2515module_init(sysc_init);
2516
2517static void __exit sysc_exit(void)
2518{
2519 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
2520 platform_driver_unregister(&sysc_driver);
2521}
2522module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002523
2524MODULE_DESCRIPTION("TI sysc interconnect target driver");
2525MODULE_LICENSE("GPL v2");