blob: 778bd0fffec094bd08e2174ec97f8d66a3966b32 [file] [log] [blame]
Tony Lindgren0eecc632017-10-10 14:23:43 -07001/*
2 * ti-sysc.c - Texas Instruments sysc interconnect target driver
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/io.h>
15#include <linux/clk.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080016#include <linux/clkdev.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080017#include <linux/delay.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070018#include <linux/module.h>
19#include <linux/platform_device.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080020#include <linux/pm_domain.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070021#include <linux/pm_runtime.h>
Tony Lindgren50622362018-04-16 10:20:27 -070022#include <linux/reset.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070023#include <linux/of_address.h>
24#include <linux/of_platform.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080025#include <linux/slab.h>
Faiz Abbas596e7952018-07-09 22:18:39 +053026#include <linux/iopoll.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080027
Tony Lindgren70a65242017-12-15 09:41:09 -080028#include <linux/platform_data/ti-sysc.h>
29
30#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070031
Faiz Abbas596e7952018-07-09 22:18:39 +053032#define MAX_MODULE_SOFTRESET_WAIT 10000
33
Tony Lindgren0eecc632017-10-10 14:23:43 -070034static const char * const reg_names[] = { "rev", "sysc", "syss", };
35
36enum sysc_clocks {
37 SYSC_FCK,
38 SYSC_ICK,
Tony Lindgren09dfe582018-04-16 10:25:52 -070039 SYSC_OPTFCK0,
40 SYSC_OPTFCK1,
41 SYSC_OPTFCK2,
42 SYSC_OPTFCK3,
43 SYSC_OPTFCK4,
44 SYSC_OPTFCK5,
45 SYSC_OPTFCK6,
46 SYSC_OPTFCK7,
Tony Lindgren0eecc632017-10-10 14:23:43 -070047 SYSC_MAX_CLOCKS,
48};
49
Tony Lindgrena54275f2019-03-21 11:00:21 -070050static const char * const clock_names[SYSC_MAX_CLOCKS] = {
51 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
52 "opt5", "opt6", "opt7",
53};
Tony Lindgren0eecc632017-10-10 14:23:43 -070054
Tony Lindgrenc5a2de92017-12-15 09:41:23 -080055#define SYSC_IDLEMODE_MASK 3
56#define SYSC_CLOCKACTIVITY_MASK 3
57
Tony Lindgren0eecc632017-10-10 14:23:43 -070058/**
59 * struct sysc - TI sysc interconnect target module registers and capabilities
60 * @dev: struct device pointer
61 * @module_pa: physical address of the interconnect target module
62 * @module_size: size of the interconnect target module
63 * @module_va: virtual address of the interconnect target module
64 * @offsets: register offsets from module base
65 * @clocks: clocks used by the interconnect target module
Tony Lindgren09dfe582018-04-16 10:25:52 -070066 * @clock_roles: clock role names for the found clocks
67 * @nr_clocks: number of clocks used by the interconnect target module
Tony Lindgren0eecc632017-10-10 14:23:43 -070068 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -080069 * @cap: interconnect target module capabilities
70 * @cfg: interconnect target module configuration
Tony Lindgren566a9b052017-12-15 09:41:19 -080071 * @name: name if available
72 * @revision: interconnect target module revision
Tony Lindgren62020f22018-02-22 13:59:44 -080073 * @needs_resume: runtime resume needed on resume from suspend
Tony Lindgren0eecc632017-10-10 14:23:43 -070074 */
75struct sysc {
76 struct device *dev;
77 u64 module_pa;
78 u32 module_size;
79 void __iomem *module_va;
80 int offsets[SYSC_MAX_REGS];
Tony Lindgrena3e92e72019-03-21 11:00:21 -070081 struct ti_sysc_module_data *mdata;
Tony Lindgren09dfe582018-04-16 10:25:52 -070082 struct clk **clocks;
83 const char **clock_roles;
84 int nr_clocks;
Tony Lindgren50622362018-04-16 10:20:27 -070085 struct reset_control *rsts;
Tony Lindgren0eecc632017-10-10 14:23:43 -070086 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -080087 const struct sysc_capabilities *cap;
88 struct sysc_config cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -080089 struct ti_sysc_cookie cookie;
Tony Lindgren566a9b052017-12-15 09:41:19 -080090 const char *name;
91 u32 revision;
Tony Lindgren62020f22018-02-22 13:59:44 -080092 bool enabled;
93 bool needs_resume;
Tony Lindgrena885f0f2018-02-22 14:03:48 -080094 bool child_needs_resume;
Tony Lindgren76f0f772018-02-23 08:28:45 -080095 struct delayed_work idle_work;
Tony Lindgren0eecc632017-10-10 14:23:43 -070096};
97
Tony Lindgren4014c082018-12-10 14:11:26 -080098static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
99 bool is_child);
100
Tony Lindgrenb7182b42019-03-21 11:00:21 -0700101static void sysc_write(struct sysc *ddata, int offset, u32 value)
Faiz Abbas596e7952018-07-09 22:18:39 +0530102{
103 writel_relaxed(value, ddata->module_va + offset);
104}
105
Tony Lindgren566a9b052017-12-15 09:41:19 -0800106static u32 sysc_read(struct sysc *ddata, int offset)
107{
108 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
109 u32 val;
110
111 val = readw_relaxed(ddata->module_va + offset);
112 val |= (readw_relaxed(ddata->module_va + offset + 4) << 16);
113
114 return val;
115 }
116
117 return readl_relaxed(ddata->module_va + offset);
118}
119
Tony Lindgren09dfe582018-04-16 10:25:52 -0700120static bool sysc_opt_clks_needed(struct sysc *ddata)
121{
122 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
123}
124
Tony Lindgren0eecc632017-10-10 14:23:43 -0700125static u32 sysc_read_revision(struct sysc *ddata)
126{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800127 int offset = ddata->offsets[SYSC_REVISION];
128
129 if (offset < 0)
130 return 0;
131
132 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700133}
134
Tony Lindgrena54275f2019-03-21 11:00:21 -0700135static int sysc_add_named_clock_from_child(struct sysc *ddata,
136 const char *name,
137 const char *optfck_name)
138{
139 struct device_node *np = ddata->dev->of_node;
140 struct device_node *child;
141 struct clk_lookup *cl;
142 struct clk *clock;
143 const char *n;
144
145 if (name)
146 n = name;
147 else
148 n = optfck_name;
149
150 /* Does the clock alias already exist? */
151 clock = of_clk_get_by_name(np, n);
152 if (!IS_ERR(clock)) {
153 clk_put(clock);
154
155 return 0;
156 }
157
158 child = of_get_next_available_child(np, NULL);
159 if (!child)
160 return -ENODEV;
161
162 clock = devm_get_clk_from_child(ddata->dev, child, name);
163 if (IS_ERR(clock))
164 return PTR_ERR(clock);
165
166 /*
167 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
168 * limit for clk_get(). If cl ever needs to be freed, it should be done
169 * with clkdev_drop().
170 */
171 cl = kcalloc(1, sizeof(*cl), GFP_KERNEL);
172 if (!cl)
173 return -ENOMEM;
174
175 cl->con_id = n;
176 cl->dev_id = dev_name(ddata->dev);
177 cl->clk = clock;
178 clkdev_add(cl);
179
180 clk_put(clock);
181
182 return 0;
183}
184
185static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
186{
187 const char *optfck_name;
188 int error, index;
189
190 if (ddata->nr_clocks < SYSC_OPTFCK0)
191 index = SYSC_OPTFCK0;
192 else
193 index = ddata->nr_clocks;
194
195 if (name)
196 optfck_name = name;
197 else
198 optfck_name = clock_names[index];
199
200 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
201 if (error)
202 return error;
203
204 ddata->clock_roles[index] = optfck_name;
205 ddata->nr_clocks++;
206
207 return 0;
208}
209
Tony Lindgren09dfe582018-04-16 10:25:52 -0700210static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700211{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700212 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700213
Tony Lindgren09dfe582018-04-16 10:25:52 -0700214 if (!strncmp(clock_names[SYSC_FCK], name, 3))
215 index = SYSC_FCK;
216 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
217 index = SYSC_ICK;
218
219 if (index < 0) {
220 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700221 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700222 index = i;
223 break;
224 }
225 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700226 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700227
228 if (index < 0) {
229 dev_err(ddata->dev, "clock %s not added\n", name);
230 return index;
231 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700232
233 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
234 if (IS_ERR(ddata->clocks[index])) {
235 if (PTR_ERR(ddata->clocks[index]) == -ENOENT)
236 return 0;
237
238 dev_err(ddata->dev, "clock get error for %s: %li\n",
239 name, PTR_ERR(ddata->clocks[index]));
240
241 return PTR_ERR(ddata->clocks[index]);
242 }
243
244 error = clk_prepare(ddata->clocks[index]);
245 if (error) {
246 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
247 name, error);
248
249 return error;
250 }
251
252 return 0;
253}
254
255static int sysc_get_clocks(struct sysc *ddata)
256{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700257 struct device_node *np = ddata->dev->of_node;
258 struct property *prop;
259 const char *name;
260 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700261
Kees Cook20749052018-06-18 10:45:49 -0700262 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700263 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700264 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700265 GFP_KERNEL);
266 if (!ddata->clock_roles)
267 return -ENOMEM;
268
269 of_property_for_each_string(np, "clock-names", prop, name) {
270 if (!strncmp(clock_names[SYSC_FCK], name, 3))
271 nr_fck++;
272 if (!strncmp(clock_names[SYSC_ICK], name, 3))
273 nr_ick++;
274 ddata->clock_roles[ddata->nr_clocks] = name;
275 ddata->nr_clocks++;
276 }
277
278 if (ddata->nr_clocks < 1)
279 return 0;
280
Tony Lindgrena54275f2019-03-21 11:00:21 -0700281 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
282 error = sysc_init_ext_opt_clock(ddata, NULL);
283 if (error)
284 return error;
285 }
286
Tony Lindgren09dfe582018-04-16 10:25:52 -0700287 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
288 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
289
290 return -EINVAL;
291 }
292
293 if (nr_fck > 1 || nr_ick > 1) {
294 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
295
296 return -EINVAL;
297 }
298
Kees Cook20749052018-06-18 10:45:49 -0700299 ddata->clocks = devm_kcalloc(ddata->dev,
300 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700301 GFP_KERNEL);
302 if (!ddata->clocks)
303 return -ENOMEM;
304
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800305 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
306 const char *name = ddata->clock_roles[i];
307
308 if (!name)
309 continue;
310
311 error = sysc_get_one_clock(ddata, name);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700312 if (error && error != -ENOENT)
313 return error;
314 }
315
316 return 0;
317}
318
Tony Lindgrend8789702019-03-21 11:00:21 -0700319static int sysc_enable_main_clocks(struct sysc *ddata)
320{
321 struct clk *clock;
322 int i, error;
323
324 if (!ddata->clocks)
325 return 0;
326
327 for (i = 0; i < SYSC_OPTFCK0; i++) {
328 clock = ddata->clocks[i];
329
330 /* Main clocks may not have ick */
331 if (IS_ERR_OR_NULL(clock))
332 continue;
333
334 error = clk_enable(clock);
335 if (error)
336 goto err_disable;
337 }
338
339 return 0;
340
341err_disable:
342 for (i--; i >= 0; i--) {
343 clock = ddata->clocks[i];
344
345 /* Main clocks may not have ick */
346 if (IS_ERR_OR_NULL(clock))
347 continue;
348
349 clk_disable(clock);
350 }
351
352 return error;
353}
354
355static void sysc_disable_main_clocks(struct sysc *ddata)
356{
357 struct clk *clock;
358 int i;
359
360 if (!ddata->clocks)
361 return;
362
363 for (i = 0; i < SYSC_OPTFCK0; i++) {
364 clock = ddata->clocks[i];
365 if (IS_ERR_OR_NULL(clock))
366 continue;
367
368 clk_disable(clock);
369 }
370}
371
372static int sysc_enable_opt_clocks(struct sysc *ddata)
373{
374 struct clk *clock;
375 int i, error;
376
377 if (!ddata->clocks)
378 return 0;
379
380 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
381 clock = ddata->clocks[i];
382
383 /* Assume no holes for opt clocks */
384 if (IS_ERR_OR_NULL(clock))
385 return 0;
386
387 error = clk_enable(clock);
388 if (error)
389 goto err_disable;
390 }
391
392 return 0;
393
394err_disable:
395 for (i--; i >= 0; i--) {
396 clock = ddata->clocks[i];
397 if (IS_ERR_OR_NULL(clock))
398 continue;
399
400 clk_disable(clock);
401 }
402
403 return error;
404}
405
406static void sysc_disable_opt_clocks(struct sysc *ddata)
407{
408 struct clk *clock;
409 int i;
410
411 if (!ddata->clocks)
412 return;
413
414 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
415 clock = ddata->clocks[i];
416
417 /* Assume no holes for opt clocks */
418 if (IS_ERR_OR_NULL(clock))
419 return;
420
421 clk_disable(clock);
422 }
423}
424
Tony Lindgren0eecc632017-10-10 14:23:43 -0700425/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700426 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700427 * @ddata: device driver data
428 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700429 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700430 */
431static int sysc_init_resets(struct sysc *ddata)
432{
Tony Lindgren50622362018-04-16 10:20:27 -0700433 ddata->rsts =
434 devm_reset_control_array_get_optional_exclusive(ddata->dev);
435 if (IS_ERR(ddata->rsts))
436 return PTR_ERR(ddata->rsts);
437
Tony Lindgren50622362018-04-16 10:20:27 -0700438 return 0;
439}
440
441/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700442 * sysc_parse_and_check_child_range - parses module IO region from ranges
443 * @ddata: device driver data
444 *
445 * In general we only need rev, syss, and sysc registers and not the whole
446 * module range. But we do want the offsets for these registers from the
447 * module base. This allows us to check them against the legacy hwmod
448 * platform data. Let's also check the ranges are configured properly.
449 */
450static int sysc_parse_and_check_child_range(struct sysc *ddata)
451{
452 struct device_node *np = ddata->dev->of_node;
453 const __be32 *ranges;
454 u32 nr_addr, nr_size;
455 int len, error;
456
457 ranges = of_get_property(np, "ranges", &len);
458 if (!ranges) {
459 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
460
461 return -ENOENT;
462 }
463
464 len /= sizeof(*ranges);
465
466 if (len < 3) {
467 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
468
469 return -EINVAL;
470 }
471
472 error = of_property_read_u32(np, "#address-cells", &nr_addr);
473 if (error)
474 return -ENOENT;
475
476 error = of_property_read_u32(np, "#size-cells", &nr_size);
477 if (error)
478 return -ENOENT;
479
480 if (nr_addr != 1 || nr_size != 1) {
481 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
482
483 return -EINVAL;
484 }
485
486 ranges++;
487 ddata->module_pa = of_translate_address(np, ranges++);
488 ddata->module_size = be32_to_cpup(ranges);
489
Tony Lindgren0eecc632017-10-10 14:23:43 -0700490 return 0;
491}
492
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800493static struct device_node *stdout_path;
494
495static void sysc_init_stdout_path(struct sysc *ddata)
496{
497 struct device_node *np = NULL;
498 const char *uart;
499
500 if (IS_ERR(stdout_path))
501 return;
502
503 if (stdout_path)
504 return;
505
506 np = of_find_node_by_path("/chosen");
507 if (!np)
508 goto err;
509
510 uart = of_get_property(np, "stdout-path", NULL);
511 if (!uart)
512 goto err;
513
514 np = of_find_node_by_path(uart);
515 if (!np)
516 goto err;
517
518 stdout_path = np;
519
520 return;
521
522err:
523 stdout_path = ERR_PTR(-ENODEV);
524}
525
526static void sysc_check_quirk_stdout(struct sysc *ddata,
527 struct device_node *np)
528{
529 sysc_init_stdout_path(ddata);
530 if (np != stdout_path)
531 return;
532
533 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
534 SYSC_QUIRK_NO_RESET_ON_INIT;
535}
536
Tony Lindgren0eecc632017-10-10 14:23:43 -0700537/**
538 * sysc_check_one_child - check child configuration
539 * @ddata: device driver data
540 * @np: child device node
541 *
542 * Let's avoid messy situations where we have new interconnect target
543 * node but children have "ti,hwmods". These belong to the interconnect
544 * target node and are managed by this driver.
545 */
546static int sysc_check_one_child(struct sysc *ddata,
547 struct device_node *np)
548{
549 const char *name;
550
551 name = of_get_property(np, "ti,hwmods", NULL);
552 if (name)
553 dev_warn(ddata->dev, "really a child ti,hwmods property?");
554
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800555 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800556 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800557
Tony Lindgren0eecc632017-10-10 14:23:43 -0700558 return 0;
559}
560
561static int sysc_check_children(struct sysc *ddata)
562{
563 struct device_node *child;
564 int error;
565
566 for_each_child_of_node(ddata->dev->of_node, child) {
567 error = sysc_check_one_child(ddata, child);
568 if (error)
569 return error;
570 }
571
572 return 0;
573}
574
Tony Lindgrena7199e22017-12-15 09:41:14 -0800575/*
576 * So far only I2C uses 16-bit read access with clockactivity with revision
577 * in two registers with stride of 4. We can detect this based on the rev
578 * register size to configure things far enough to be able to properly read
579 * the revision register.
580 */
581static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
582{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800583 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800584 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800585}
586
Tony Lindgren0eecc632017-10-10 14:23:43 -0700587/**
588 * sysc_parse_one - parses the interconnect target module registers
589 * @ddata: device driver data
590 * @reg: register to parse
591 */
592static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
593{
594 struct resource *res;
595 const char *name;
596
597 switch (reg) {
598 case SYSC_REVISION:
599 case SYSC_SYSCONFIG:
600 case SYSC_SYSSTATUS:
601 name = reg_names[reg];
602 break;
603 default:
604 return -EINVAL;
605 }
606
607 res = platform_get_resource_byname(to_platform_device(ddata->dev),
608 IORESOURCE_MEM, name);
609 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700610 ddata->offsets[reg] = -ENODEV;
611
612 return 0;
613 }
614
615 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800616 if (reg == SYSC_REVISION)
617 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700618
619 return 0;
620}
621
622static int sysc_parse_registers(struct sysc *ddata)
623{
624 int i, error;
625
626 for (i = 0; i < SYSC_MAX_REGS; i++) {
627 error = sysc_parse_one(ddata, i);
628 if (error)
629 return error;
630 }
631
632 return 0;
633}
634
635/**
636 * sysc_check_registers - check for misconfigured register overlaps
637 * @ddata: device driver data
638 */
639static int sysc_check_registers(struct sysc *ddata)
640{
641 int i, j, nr_regs = 0, nr_matches = 0;
642
643 for (i = 0; i < SYSC_MAX_REGS; i++) {
644 if (ddata->offsets[i] < 0)
645 continue;
646
647 if (ddata->offsets[i] > (ddata->module_size - 4)) {
648 dev_err(ddata->dev, "register outside module range");
649
650 return -EINVAL;
651 }
652
653 for (j = 0; j < SYSC_MAX_REGS; j++) {
654 if (ddata->offsets[j] < 0)
655 continue;
656
657 if (ddata->offsets[i] == ddata->offsets[j])
658 nr_matches++;
659 }
660 nr_regs++;
661 }
662
663 if (nr_regs < 1) {
664 dev_err(ddata->dev, "missing registers\n");
665
666 return -EINVAL;
667 }
668
669 if (nr_matches > nr_regs) {
670 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
671 nr_regs, nr_matches);
672
673 return -EINVAL;
674 }
675
676 return 0;
677}
678
679/**
680 * syc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700681 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700682 *
683 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700684 * within the interconnect target module range. For example, SGX has
685 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
686 * has them at offset 0x1200 in the CPSW_WR child. Usually the
687 * the interconnect target module registers are at the beginning of
688 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700689 */
690static int sysc_ioremap(struct sysc *ddata)
691{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700692 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700693
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700694 size = max3(ddata->offsets[SYSC_REVISION],
695 ddata->offsets[SYSC_SYSCONFIG],
696 ddata->offsets[SYSC_SYSSTATUS]);
697
698 if (size < 0 || (size + sizeof(u32)) > ddata->module_size)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700699 return -EINVAL;
700
Tony Lindgren0eecc632017-10-10 14:23:43 -0700701 ddata->module_va = devm_ioremap(ddata->dev,
702 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700703 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700704 if (!ddata->module_va)
705 return -EIO;
706
707 return 0;
708}
709
710/**
711 * sysc_map_and_check_registers - ioremap and check device registers
712 * @ddata: device driver data
713 */
714static int sysc_map_and_check_registers(struct sysc *ddata)
715{
716 int error;
717
718 error = sysc_parse_and_check_child_range(ddata);
719 if (error)
720 return error;
721
722 error = sysc_check_children(ddata);
723 if (error)
724 return error;
725
726 error = sysc_parse_registers(ddata);
727 if (error)
728 return error;
729
730 error = sysc_ioremap(ddata);
731 if (error)
732 return error;
733
734 error = sysc_check_registers(ddata);
735 if (error)
736 return error;
737
738 return 0;
739}
740
741/**
742 * sysc_show_rev - read and show interconnect target module revision
743 * @bufp: buffer to print the information to
744 * @ddata: device driver data
745 */
746static int sysc_show_rev(char *bufp, struct sysc *ddata)
747{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800748 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700749
750 if (ddata->offsets[SYSC_REVISION] < 0)
751 return sprintf(bufp, ":NA");
752
Tony Lindgren566a9b052017-12-15 09:41:19 -0800753 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700754
755 return len;
756}
757
758static int sysc_show_reg(struct sysc *ddata,
759 char *bufp, enum sysc_registers reg)
760{
761 if (ddata->offsets[reg] < 0)
762 return sprintf(bufp, ":NA");
763
764 return sprintf(bufp, ":%x", ddata->offsets[reg]);
765}
766
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800767static int sysc_show_name(char *bufp, struct sysc *ddata)
768{
769 if (!ddata->name)
770 return 0;
771
772 return sprintf(bufp, ":%s", ddata->name);
773}
774
Tony Lindgren0eecc632017-10-10 14:23:43 -0700775/**
776 * sysc_show_registers - show information about interconnect target module
777 * @ddata: device driver data
778 */
779static void sysc_show_registers(struct sysc *ddata)
780{
781 char buf[128];
782 char *bufp = buf;
783 int i;
784
785 for (i = 0; i < SYSC_MAX_REGS; i++)
786 bufp += sysc_show_reg(ddata, bufp, i);
787
788 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800789 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700790
791 dev_dbg(ddata->dev, "%llx:%x%s\n",
792 ddata->module_pa, ddata->module_size,
793 buf);
794}
795
Tony Lindgrenff437282019-03-21 11:00:21 -0700796static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
797 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700798{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800799 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -0700800 int error;
801
802 pdata = dev_get_platdata(ddata->dev);
803 if (!pdata)
804 return 0;
805
806 if (!pdata->idle_module)
807 return -ENODEV;
808
809 error = pdata->idle_module(dev, &ddata->cookie);
810 if (error)
811 dev_err(dev, "%s: could not idle: %i\n",
812 __func__, error);
813
814 return 0;
815}
816
817static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
818 struct sysc *ddata)
819{
820 struct ti_sysc_platform_data *pdata;
821 int error;
822
823 pdata = dev_get_platdata(ddata->dev);
824 if (!pdata)
825 return 0;
826
827 if (!pdata->enable_module)
828 return -ENODEV;
829
830 error = pdata->enable_module(dev, &ddata->cookie);
831 if (error)
832 dev_err(dev, "%s: could not enable: %i\n",
833 __func__, error);
834
835 return 0;
836}
837
838static int __maybe_unused sysc_runtime_suspend(struct device *dev)
839{
Tony Lindgren0eecc632017-10-10 14:23:43 -0700840 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -0700841 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700842
843 ddata = dev_get_drvdata(dev);
844
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800845 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700846 return 0;
847
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800848 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -0700849 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -0700850 if (error)
851 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800852 }
853
Tony Lindgrend8789702019-03-21 11:00:21 -0700854 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -0700855
Tony Lindgrend8789702019-03-21 11:00:21 -0700856 if (sysc_opt_clks_needed(ddata))
857 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700858
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800859 ddata->enabled = false;
860
861 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700862}
863
Arnd Bergmanna4a5d492017-10-13 11:25:32 +0200864static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700865{
866 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -0700867 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700868
869 ddata = dev_get_drvdata(dev);
870
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800871 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700872 return 0;
873
Tony Lindgrend8789702019-03-21 11:00:21 -0700874 if (sysc_opt_clks_needed(ddata)) {
875 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700876 if (error)
877 return error;
878 }
879
Tony Lindgrend8789702019-03-21 11:00:21 -0700880 error = sysc_enable_main_clocks(ddata);
881 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -0700882 goto err_opt_clocks;
883
884 if (ddata->legacy_mode) {
885 error = sysc_runtime_resume_legacy(dev, ddata);
886 if (error)
887 goto err_main_clocks;
888 }
Tony Lindgrend8789702019-03-21 11:00:21 -0700889
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800890 ddata->enabled = true;
891
Tony Lindgrend8789702019-03-21 11:00:21 -0700892 return 0;
893
894err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -0700895 sysc_disable_main_clocks(ddata);
896err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -0700897 if (sysc_opt_clks_needed(ddata))
898 sysc_disable_opt_clocks(ddata);
899
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800900 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700901}
902
Tony Lindgrenf5e802032018-10-01 09:33:28 -0700903static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -0800904{
905 struct sysc *ddata;
906
907 ddata = dev_get_drvdata(dev);
908
Tony Lindgren40d9f912018-09-24 12:16:54 -0700909 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -0700910 return 0;
911
Tony Lindgrenf5e802032018-10-01 09:33:28 -0700912 return pm_runtime_force_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -0800913}
914
Tony Lindgrenf5e802032018-10-01 09:33:28 -0700915static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -0800916{
917 struct sysc *ddata;
918
919 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -0700920
Tony Lindgren40d9f912018-09-24 12:16:54 -0700921 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -0700922 return 0;
923
Tony Lindgrenf5e802032018-10-01 09:33:28 -0700924 return pm_runtime_force_resume(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -0700925}
926
Tony Lindgren0eecc632017-10-10 14:23:43 -0700927static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -0700928 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700929 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
930 sysc_runtime_resume,
931 NULL)
932};
933
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800934/* Module revision register based quirks */
935struct sysc_revision_quirk {
936 const char *name;
937 u32 base;
938 int rev_offset;
939 int sysc_offset;
940 int syss_offset;
941 u32 revision;
942 u32 revision_mask;
943 u32 quirks;
944};
945
946#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
947 optrev_val, optrevmask, optquirkmask) \
948 { \
949 .name = (optname), \
950 .base = (optbase), \
951 .rev_offset = (optrev), \
952 .sysc_offset = (optsysc), \
953 .syss_offset = (optsyss), \
954 .revision = (optrev_val), \
955 .revision_mask = (optrevmask), \
956 .quirks = (optquirkmask), \
957 }
958
959static const struct sysc_revision_quirk sysc_revision_quirks[] = {
960 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -0700961 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700962 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800963 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
964 SYSC_QUIRK_LEGACY_IDLE),
965 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff,
966 SYSC_QUIRK_LEGACY_IDLE),
967 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
968 SYSC_QUIRK_LEGACY_IDLE),
969 SYSC_QUIRK("smartreflex", 0, -1, 0x24, -1, 0x00000000, 0xffffffff,
970 SYSC_QUIRK_LEGACY_IDLE),
971 SYSC_QUIRK("smartreflex", 0, -1, 0x38, -1, 0x00000000, 0xffffffff,
972 SYSC_QUIRK_LEGACY_IDLE),
973 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -0800974 0),
Tony Lindgren8cde5d52018-04-16 10:25:15 -0700975 /* Some timers on omap4 and later */
Tony Lindgren3a3d8022018-09-27 13:33:58 -0700976 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x50002100, 0xffffffff,
Tony Lindgren072167d2019-01-29 07:53:47 -0800977 0),
Tony Lindgren3a3d8022018-09-27 13:33:58 -0700978 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x4fff1301, 0xffff00ff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -0800979 0),
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800980 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
981 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -0700982 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -0700983 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
984 SYSC_QUIRK_LEGACY_IDLE),
985 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrend708bb12018-04-16 10:25:32 -0700986 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -0700987
Tony Lindgrena54275f2019-03-21 11:00:21 -0700988 /* Quirks that need to be set based on the module address */
989 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -1, 0x50000800, 0xffffffff,
990 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
991 SYSC_QUIRK_SWSUP_SIDLE),
992
Tony Lindgrendc4c85e2018-04-16 10:26:25 -0700993#ifdef DEBUG
Tony Lindgren1ba30692018-09-24 12:17:05 -0700994 SYSC_QUIRK("adc", 0, 0, 0x10, -1, 0x47300001, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -0700995 SYSC_QUIRK("atl", 0, 0, -1, -1, 0x0a070100, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -0700996 SYSC_QUIRK("aess", 0, 0, 0x10, -1, 0x40000000, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -0700997 SYSC_QUIRK("cm", 0, 0, -1, -1, 0x40000301, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -0700998 SYSC_QUIRK("control", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -0700999 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001000 0xffff00f0, 0),
1001 SYSC_QUIRK("dcan", 0, 0, -1, -1, 0xffffffff, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001002 SYSC_QUIRK("dcan", 0, 0, -1, -1, 0x00001401, 0xffffffff, 0),
1003 SYSC_QUIRK("dwc3", 0, 0, 0x10, -1, 0x500a0200, 0xffffffff, 0),
1004 SYSC_QUIRK("epwmss", 0, 0, 0x4, -1, 0x47400001, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001005 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -1, 0, 0, 0),
1006 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001007 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001008 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
1009 SYSC_QUIRK("iss", 0, 0, 0x10, -1, 0x40000101, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001010 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001011 SYSC_QUIRK("lcdc", 0, 0, 0x54, -1, 0x4f201000, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001012 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44306302, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001013 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44307b02, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001014 SYSC_QUIRK("mcbsp", 0, -1, 0x8c, -1, 0, 0, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001015 SYSC_QUIRK("mcspi", 0, 0, 0x10, -1, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001016 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001017 SYSC_QUIRK("mailbox", 0, 0, 0x10, -1, 0x00000400, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001018 SYSC_QUIRK("m3", 0, 0, -1, -1, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001019 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001020 SYSC_QUIRK("ocp2scp", 0, 0, -1, -1, 0x50060007, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001021 SYSC_QUIRK("padconf", 0, 0, 0x10, -1, 0x4fff0800, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001022 SYSC_QUIRK("padconf", 0, 0, -1, -1, 0x40001100, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001023 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000100, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001024 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x00004102, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001025 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000400, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001026 SYSC_QUIRK("scm", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001027 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4e8b0100, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001028 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4f000100, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001029 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001030 SYSC_QUIRK("scrm", 0, 0, -1, -1, 0x00000010, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001031 SYSC_QUIRK("sdio", 0, 0, 0x10, -1, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001032 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001033 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001034 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40000902, 0xffffffff, 0),
1035 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40002903, 0xffffffff, 0),
1036 SYSC_QUIRK("spinlock", 0, 0, 0x10, -1, 0x50020000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001037 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -1, 0x00000020, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001038 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -1, 0x4eb01908, 0xffff00f0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001039 SYSC_QUIRK("timer32k", 0, 0, 0x4, -1, 0x00000060, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001040 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001041 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001042 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001043 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -1, 0x50700101, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001044 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1045 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001046 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0, 0),
1047 SYSC_QUIRK("vfpe", 0, 0, 0x104, -1, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001048#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001049};
1050
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001051/*
1052 * Early quirks based on module base and register offsets only that are
1053 * needed before the module revision can be read
1054 */
1055static void sysc_init_early_quirks(struct sysc *ddata)
1056{
1057 const struct sysc_revision_quirk *q;
1058 int i;
1059
1060 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1061 q = &sysc_revision_quirks[i];
1062
1063 if (!q->base)
1064 continue;
1065
1066 if (q->base != ddata->module_pa)
1067 continue;
1068
1069 if (q->rev_offset >= 0 &&
1070 q->rev_offset != ddata->offsets[SYSC_REVISION])
1071 continue;
1072
1073 if (q->sysc_offset >= 0 &&
1074 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1075 continue;
1076
1077 if (q->syss_offset >= 0 &&
1078 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1079 continue;
1080
1081 ddata->name = q->name;
1082 ddata->cfg.quirks |= q->quirks;
1083 }
1084}
1085
1086/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001087static void sysc_init_revision_quirks(struct sysc *ddata)
1088{
1089 const struct sysc_revision_quirk *q;
1090 int i;
1091
1092 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1093 q = &sysc_revision_quirks[i];
1094
1095 if (q->base && q->base != ddata->module_pa)
1096 continue;
1097
1098 if (q->rev_offset >= 0 &&
1099 q->rev_offset != ddata->offsets[SYSC_REVISION])
1100 continue;
1101
1102 if (q->sysc_offset >= 0 &&
1103 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1104 continue;
1105
1106 if (q->syss_offset >= 0 &&
1107 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1108 continue;
1109
1110 if (q->revision == ddata->revision ||
1111 (q->revision & q->revision_mask) ==
1112 (ddata->revision & q->revision_mask)) {
1113 ddata->name = q->name;
1114 ddata->cfg.quirks |= q->quirks;
1115 }
1116 }
1117}
1118
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001119/*
1120 * Note that pdata->init_module() typically does a reset first. After
1121 * pdata->init_module() is done, PM runtime can be used for the interconnect
1122 * target module.
1123 */
1124static int sysc_legacy_init(struct sysc *ddata)
1125{
1126 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1127 int error;
1128
1129 if (!ddata->legacy_mode || !pdata || !pdata->init_module)
1130 return 0;
1131
1132 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
1133 if (error == -EEXIST)
1134 error = 0;
1135
1136 return error;
1137}
1138
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001139/**
1140 * sysc_rstctrl_reset_deassert - deassert rstctrl reset
1141 * @ddata: device driver data
1142 * @reset: reset before deassert
1143 *
1144 * A module can have both OCP softreset control and external rstctrl.
1145 * If more complicated rstctrl resets are needed, please handle these
1146 * directly from the child device driver and map only the module reset
1147 * for the parent interconnect target module device.
1148 *
1149 * Automatic reset of the module on init can be skipped with the
1150 * "ti,no-reset-on-init" device tree property.
1151 */
1152static int sysc_rstctrl_reset_deassert(struct sysc *ddata, bool reset)
1153{
1154 int error;
1155
1156 if (!ddata->rsts)
1157 return 0;
1158
1159 if (reset) {
1160 error = reset_control_assert(ddata->rsts);
1161 if (error)
1162 return error;
1163 }
1164
1165 return reset_control_deassert(ddata->rsts);
1166}
1167
Faiz Abbas596e7952018-07-09 22:18:39 +05301168static int sysc_reset(struct sysc *ddata)
1169{
1170 int offset = ddata->offsets[SYSC_SYSCONFIG];
1171 int val;
1172
1173 if (ddata->legacy_mode || offset < 0 ||
1174 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
1175 return 0;
1176
1177 /*
1178 * Currently only support reset status in sysstatus.
1179 * Warn and return error in all other cases
1180 */
1181 if (!ddata->cfg.syss_mask) {
1182 dev_err(ddata->dev, "No ti,syss-mask. Reset failed\n");
1183 return -EINVAL;
1184 }
1185
1186 val = sysc_read(ddata, offset);
1187 val |= (0x1 << ddata->cap->regbits->srst_shift);
1188 sysc_write(ddata, offset, val);
1189
1190 /* Poll on reset status */
1191 offset = ddata->offsets[SYSC_SYSSTATUS];
1192
1193 return readl_poll_timeout(ddata->module_va + offset, val,
1194 (val & ddata->cfg.syss_mask) == 0x0,
1195 100, MAX_MODULE_SOFTRESET_WAIT);
1196}
1197
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001198/*
1199 * At this point the module is configured enough to read the revision but
1200 * module may not be completely configured yet to use PM runtime. Enable
1201 * all clocks directly during init to configure the quirks needed for PM
1202 * runtime based on the revision register.
1203 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08001204static int sysc_init_module(struct sysc *ddata)
1205{
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001206 int error = 0;
1207 bool manage_clocks = true;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001208 bool reset = true;
1209
1210 if (ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
1211 reset = false;
1212
1213 error = sysc_rstctrl_reset_deassert(ddata, reset);
1214 if (error)
1215 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001216
Tony Lindgren386cb762019-03-22 07:49:30 -07001217 if (ddata->cfg.quirks &
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001218 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))
1219 manage_clocks = false;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001220
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001221 if (manage_clocks) {
1222 error = sysc_enable_opt_clocks(ddata);
1223 if (error)
1224 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001225
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001226 error = sysc_enable_main_clocks(ddata);
1227 if (error)
1228 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05301229 }
1230
Tony Lindgren566a9b052017-12-15 09:41:19 -08001231 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001232 sysc_init_revision_quirks(ddata);
1233
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001234 error = sysc_legacy_init(ddata);
1235 if (error)
1236 goto err_main_clocks;
1237
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001238 error = sysc_reset(ddata);
1239 if (error)
1240 dev_err(ddata->dev, "Reset failed with %d\n", error);
1241
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001242err_main_clocks:
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001243 if (manage_clocks)
1244 sysc_disable_main_clocks(ddata);
1245err_opt_clocks:
1246 if (manage_clocks)
1247 sysc_disable_opt_clocks(ddata);
1248
1249 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001250}
1251
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001252static int sysc_init_sysc_mask(struct sysc *ddata)
1253{
1254 struct device_node *np = ddata->dev->of_node;
1255 int error;
1256 u32 val;
1257
1258 error = of_property_read_u32(np, "ti,sysc-mask", &val);
1259 if (error)
1260 return 0;
1261
1262 if (val)
1263 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
1264 else
1265 ddata->cfg.sysc_val = ddata->cap->sysc_mask;
1266
1267 return 0;
1268}
1269
1270static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
1271 const char *name)
1272{
1273 struct device_node *np = ddata->dev->of_node;
1274 struct property *prop;
1275 const __be32 *p;
1276 u32 val;
1277
1278 of_property_for_each_u32(np, name, prop, p, val) {
1279 if (val >= SYSC_NR_IDLEMODES) {
1280 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
1281 return -EINVAL;
1282 }
1283 *idlemodes |= (1 << val);
1284 }
1285
1286 return 0;
1287}
1288
1289static int sysc_init_idlemodes(struct sysc *ddata)
1290{
1291 int error;
1292
1293 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
1294 "ti,sysc-midle");
1295 if (error)
1296 return error;
1297
1298 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
1299 "ti,sysc-sidle");
1300 if (error)
1301 return error;
1302
1303 return 0;
1304}
1305
1306/*
1307 * Only some devices on omap4 and later have SYSCONFIG reset done
1308 * bit. We can detect this if there is no SYSSTATUS at all, or the
1309 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
1310 * have multiple bits for the child devices like OHCI and EHCI.
1311 * Depends on SYSC being parsed first.
1312 */
1313static int sysc_init_syss_mask(struct sysc *ddata)
1314{
1315 struct device_node *np = ddata->dev->of_node;
1316 int error;
1317 u32 val;
1318
1319 error = of_property_read_u32(np, "ti,syss-mask", &val);
1320 if (error) {
1321 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
1322 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
1323 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1324 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1325
1326 return 0;
1327 }
1328
1329 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1330 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1331
1332 ddata->cfg.syss_mask = val;
1333
1334 return 0;
1335}
1336
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001337/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001338 * Many child device drivers need to have fck and opt clocks available
1339 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001340 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001341static int sysc_child_add_named_clock(struct sysc *ddata,
1342 struct device *child,
1343 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001344{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001345 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001346 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001347 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001348
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001349 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001350 return 0;
1351
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001352 clk = clk_get(child, name);
1353 if (!IS_ERR(clk)) {
1354 clk_put(clk);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001355
1356 return -EEXIST;
1357 }
1358
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001359 clk = clk_get(ddata->dev, name);
1360 if (IS_ERR(clk))
1361 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001362
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001363 l = clkdev_create(clk, name, dev_name(child));
1364 if (!l)
1365 error = -ENOMEM;
1366
1367 clk_put(clk);
1368
1369 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001370}
1371
Tony Lindgren09dfe582018-04-16 10:25:52 -07001372static int sysc_child_add_clocks(struct sysc *ddata,
1373 struct device *child)
1374{
1375 int i, error;
1376
1377 for (i = 0; i < ddata->nr_clocks; i++) {
1378 error = sysc_child_add_named_clock(ddata,
1379 child,
1380 ddata->clock_roles[i]);
1381 if (error && error != -EEXIST) {
1382 dev_err(ddata->dev, "could not add child clock %s: %i\n",
1383 ddata->clock_roles[i], error);
1384
1385 return error;
1386 }
1387 }
1388
1389 return 0;
1390}
1391
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001392static struct device_type sysc_device_type = {
1393};
1394
1395static struct sysc *sysc_child_to_parent(struct device *dev)
1396{
1397 struct device *parent = dev->parent;
1398
1399 if (!parent || parent->type != &sysc_device_type)
1400 return NULL;
1401
1402 return dev_get_drvdata(parent);
1403}
1404
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001405static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
1406{
1407 struct sysc *ddata;
1408 int error;
1409
1410 ddata = sysc_child_to_parent(dev);
1411
1412 error = pm_generic_runtime_suspend(dev);
1413 if (error)
1414 return error;
1415
1416 if (!ddata->enabled)
1417 return 0;
1418
1419 return sysc_runtime_suspend(ddata->dev);
1420}
1421
1422static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
1423{
1424 struct sysc *ddata;
1425 int error;
1426
1427 ddata = sysc_child_to_parent(dev);
1428
1429 if (!ddata->enabled) {
1430 error = sysc_runtime_resume(ddata->dev);
1431 if (error < 0)
1432 dev_err(ddata->dev,
1433 "%s error: %i\n", __func__, error);
1434 }
1435
1436 return pm_generic_runtime_resume(dev);
1437}
1438
1439#ifdef CONFIG_PM_SLEEP
1440static int sysc_child_suspend_noirq(struct device *dev)
1441{
1442 struct sysc *ddata;
1443 int error;
1444
1445 ddata = sysc_child_to_parent(dev);
1446
Tony Lindgrenef55f822018-04-16 10:27:15 -07001447 dev_dbg(ddata->dev, "%s %s\n", __func__,
1448 ddata->name ? ddata->name : "");
1449
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001450 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001451 if (error) {
1452 dev_err(dev, "%s error at %i: %i\n",
1453 __func__, __LINE__, error);
1454
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001455 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001456 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001457
1458 if (!pm_runtime_status_suspended(dev)) {
1459 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001460 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07001461 dev_dbg(dev, "%s busy at %i: %i\n",
1462 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001463
Tony Lindgren4f3530f2018-08-08 01:07:06 -07001464 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001465 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001466
1467 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001468 if (error) {
1469 dev_err(dev, "%s error at %i: %i\n",
1470 __func__, __LINE__, error);
1471
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001472 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001473 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001474
1475 ddata->child_needs_resume = true;
1476 }
1477
1478 return 0;
1479}
1480
1481static int sysc_child_resume_noirq(struct device *dev)
1482{
1483 struct sysc *ddata;
1484 int error;
1485
1486 ddata = sysc_child_to_parent(dev);
1487
Tony Lindgrenef55f822018-04-16 10:27:15 -07001488 dev_dbg(ddata->dev, "%s %s\n", __func__,
1489 ddata->name ? ddata->name : "");
1490
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001491 if (ddata->child_needs_resume) {
1492 ddata->child_needs_resume = false;
1493
1494 error = sysc_runtime_resume(ddata->dev);
1495 if (error)
1496 dev_err(ddata->dev,
1497 "%s runtime resume error: %i\n",
1498 __func__, error);
1499
1500 error = pm_generic_runtime_resume(dev);
1501 if (error)
1502 dev_err(ddata->dev,
1503 "%s generic runtime resume: %i\n",
1504 __func__, error);
1505 }
1506
1507 return pm_generic_resume_noirq(dev);
1508}
1509#endif
1510
Tony Lindgrenb7182b42019-03-21 11:00:21 -07001511static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001512 .ops = {
1513 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
1514 sysc_child_runtime_resume,
1515 NULL)
1516 USE_PLATFORM_PM_SLEEP_OPS
1517 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
1518 sysc_child_resume_noirq)
1519 }
1520};
1521
1522/**
1523 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
1524 * @ddata: device driver data
1525 * @child: child device driver
1526 *
1527 * Allow idle for child devices as done with _od_runtime_suspend().
1528 * Otherwise many child devices will not idle because of the permanent
1529 * parent usecount set in pm_runtime_irq_safe().
1530 *
1531 * Note that the long term solution is to just modify the child device
1532 * drivers to not set pm_runtime_irq_safe() and then this can be just
1533 * dropped.
1534 */
1535static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
1536{
1537 if (!ddata->legacy_mode)
1538 return;
1539
1540 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
1541 dev_pm_domain_set(child, &sysc_child_pm_domain);
1542}
1543
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001544static int sysc_notifier_call(struct notifier_block *nb,
1545 unsigned long event, void *device)
1546{
1547 struct device *dev = device;
1548 struct sysc *ddata;
1549 int error;
1550
1551 ddata = sysc_child_to_parent(dev);
1552 if (!ddata)
1553 return NOTIFY_DONE;
1554
1555 switch (event) {
1556 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07001557 error = sysc_child_add_clocks(ddata, dev);
1558 if (error)
1559 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001560 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001561 break;
1562 default:
1563 break;
1564 }
1565
1566 return NOTIFY_DONE;
1567}
1568
1569static struct notifier_block sysc_nb = {
1570 .notifier_call = sysc_notifier_call,
1571};
1572
Tony Lindgren566a9b052017-12-15 09:41:19 -08001573/* Device tree configured quirks */
1574struct sysc_dts_quirk {
1575 const char *name;
1576 u32 mask;
1577};
1578
1579static const struct sysc_dts_quirk sysc_dts_quirks[] = {
1580 { .name = "ti,no-idle-on-init",
1581 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
1582 { .name = "ti,no-reset-on-init",
1583 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07001584 { .name = "ti,no-idle",
1585 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08001586};
1587
Tony Lindgren4014c082018-12-10 14:11:26 -08001588static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
1589 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08001590{
Tony Lindgren566a9b052017-12-15 09:41:19 -08001591 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08001592 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001593
1594 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08001595 const char *name = sysc_dts_quirks[i].name;
1596
1597 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08001598 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08001599 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001600
1601 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08001602 if (is_child) {
1603 dev_warn(ddata->dev,
1604 "dts flag should be at module level for %s\n",
1605 name);
1606 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08001607 }
Tony Lindgren4014c082018-12-10 14:11:26 -08001608}
Tony Lindgren566a9b052017-12-15 09:41:19 -08001609
Tony Lindgren4014c082018-12-10 14:11:26 -08001610static int sysc_init_dts_quirks(struct sysc *ddata)
1611{
1612 struct device_node *np = ddata->dev->of_node;
1613 int error;
1614 u32 val;
1615
1616 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
1617
1618 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08001619 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
1620 if (!error) {
1621 if (val > 255) {
1622 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
1623 val);
1624 }
1625
1626 ddata->cfg.srst_udelay = (u8)val;
1627 }
1628
1629 return 0;
1630}
1631
Tony Lindgren0eecc632017-10-10 14:23:43 -07001632static void sysc_unprepare(struct sysc *ddata)
1633{
1634 int i;
1635
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07001636 if (!ddata->clocks)
1637 return;
1638
Tony Lindgren0eecc632017-10-10 14:23:43 -07001639 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
1640 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
1641 clk_unprepare(ddata->clocks[i]);
1642 }
1643}
1644
Tony Lindgren70a65242017-12-15 09:41:09 -08001645/*
1646 * Common sysc register bits found on omap2, also known as type1
1647 */
1648static const struct sysc_regbits sysc_regbits_omap2 = {
1649 .dmadisable_shift = -ENODEV,
1650 .midle_shift = 12,
1651 .sidle_shift = 3,
1652 .clkact_shift = 8,
1653 .emufree_shift = 5,
1654 .enwkup_shift = 2,
1655 .srst_shift = 1,
1656 .autoidle_shift = 0,
1657};
1658
1659static const struct sysc_capabilities sysc_omap2 = {
1660 .type = TI_SYSC_OMAP2,
1661 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
1662 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
1663 SYSC_OMAP2_AUTOIDLE,
1664 .regbits = &sysc_regbits_omap2,
1665};
1666
1667/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
1668static const struct sysc_capabilities sysc_omap2_timer = {
1669 .type = TI_SYSC_OMAP2_TIMER,
1670 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
1671 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
1672 SYSC_OMAP2_AUTOIDLE,
1673 .regbits = &sysc_regbits_omap2,
1674 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
1675};
1676
1677/*
1678 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
1679 * with different sidle position
1680 */
1681static const struct sysc_regbits sysc_regbits_omap3_sham = {
1682 .dmadisable_shift = -ENODEV,
1683 .midle_shift = -ENODEV,
1684 .sidle_shift = 4,
1685 .clkact_shift = -ENODEV,
1686 .enwkup_shift = -ENODEV,
1687 .srst_shift = 1,
1688 .autoidle_shift = 0,
1689 .emufree_shift = -ENODEV,
1690};
1691
1692static const struct sysc_capabilities sysc_omap3_sham = {
1693 .type = TI_SYSC_OMAP3_SHAM,
1694 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
1695 .regbits = &sysc_regbits_omap3_sham,
1696};
1697
1698/*
1699 * AES register bits found on omap3 and later, a variant of
1700 * sysc_regbits_omap2 with different sidle position
1701 */
1702static const struct sysc_regbits sysc_regbits_omap3_aes = {
1703 .dmadisable_shift = -ENODEV,
1704 .midle_shift = -ENODEV,
1705 .sidle_shift = 6,
1706 .clkact_shift = -ENODEV,
1707 .enwkup_shift = -ENODEV,
1708 .srst_shift = 1,
1709 .autoidle_shift = 0,
1710 .emufree_shift = -ENODEV,
1711};
1712
1713static const struct sysc_capabilities sysc_omap3_aes = {
1714 .type = TI_SYSC_OMAP3_AES,
1715 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
1716 .regbits = &sysc_regbits_omap3_aes,
1717};
1718
1719/*
1720 * Common sysc register bits found on omap4, also known as type2
1721 */
1722static const struct sysc_regbits sysc_regbits_omap4 = {
1723 .dmadisable_shift = 16,
1724 .midle_shift = 4,
1725 .sidle_shift = 2,
1726 .clkact_shift = -ENODEV,
1727 .enwkup_shift = -ENODEV,
1728 .emufree_shift = 1,
1729 .srst_shift = 0,
1730 .autoidle_shift = -ENODEV,
1731};
1732
1733static const struct sysc_capabilities sysc_omap4 = {
1734 .type = TI_SYSC_OMAP4,
1735 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
1736 SYSC_OMAP4_SOFTRESET,
1737 .regbits = &sysc_regbits_omap4,
1738};
1739
1740static const struct sysc_capabilities sysc_omap4_timer = {
1741 .type = TI_SYSC_OMAP4_TIMER,
1742 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
1743 SYSC_OMAP4_SOFTRESET,
1744 .regbits = &sysc_regbits_omap4,
1745};
1746
1747/*
1748 * Common sysc register bits found on omap4, also known as type3
1749 */
1750static const struct sysc_regbits sysc_regbits_omap4_simple = {
1751 .dmadisable_shift = -ENODEV,
1752 .midle_shift = 2,
1753 .sidle_shift = 0,
1754 .clkact_shift = -ENODEV,
1755 .enwkup_shift = -ENODEV,
1756 .srst_shift = -ENODEV,
1757 .emufree_shift = -ENODEV,
1758 .autoidle_shift = -ENODEV,
1759};
1760
1761static const struct sysc_capabilities sysc_omap4_simple = {
1762 .type = TI_SYSC_OMAP4_SIMPLE,
1763 .regbits = &sysc_regbits_omap4_simple,
1764};
1765
1766/*
1767 * SmartReflex sysc found on omap34xx
1768 */
1769static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
1770 .dmadisable_shift = -ENODEV,
1771 .midle_shift = -ENODEV,
1772 .sidle_shift = -ENODEV,
1773 .clkact_shift = 20,
1774 .enwkup_shift = -ENODEV,
1775 .srst_shift = -ENODEV,
1776 .emufree_shift = -ENODEV,
1777 .autoidle_shift = -ENODEV,
1778};
1779
1780static const struct sysc_capabilities sysc_34xx_sr = {
1781 .type = TI_SYSC_OMAP34XX_SR,
1782 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
1783 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001784 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
1785 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08001786};
1787
1788/*
1789 * SmartReflex sysc found on omap36xx and later
1790 */
1791static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
1792 .dmadisable_shift = -ENODEV,
1793 .midle_shift = -ENODEV,
1794 .sidle_shift = 24,
1795 .clkact_shift = -ENODEV,
1796 .enwkup_shift = 26,
1797 .srst_shift = -ENODEV,
1798 .emufree_shift = -ENODEV,
1799 .autoidle_shift = -ENODEV,
1800};
1801
1802static const struct sysc_capabilities sysc_36xx_sr = {
1803 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08001804 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08001805 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001806 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08001807};
1808
1809static const struct sysc_capabilities sysc_omap4_sr = {
1810 .type = TI_SYSC_OMAP4_SR,
1811 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001812 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08001813};
1814
1815/*
1816 * McASP register bits found on omap4 and later
1817 */
1818static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
1819 .dmadisable_shift = -ENODEV,
1820 .midle_shift = -ENODEV,
1821 .sidle_shift = 0,
1822 .clkact_shift = -ENODEV,
1823 .enwkup_shift = -ENODEV,
1824 .srst_shift = -ENODEV,
1825 .emufree_shift = -ENODEV,
1826 .autoidle_shift = -ENODEV,
1827};
1828
1829static const struct sysc_capabilities sysc_omap4_mcasp = {
1830 .type = TI_SYSC_OMAP4_MCASP,
1831 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08001832 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
1833};
1834
1835/*
1836 * McASP found on dra7 and later
1837 */
1838static const struct sysc_capabilities sysc_dra7_mcasp = {
1839 .type = TI_SYSC_OMAP4_SIMPLE,
1840 .regbits = &sysc_regbits_omap4_simple,
1841 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08001842};
1843
1844/*
1845 * FS USB host found on omap4 and later
1846 */
1847static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
1848 .dmadisable_shift = -ENODEV,
1849 .midle_shift = -ENODEV,
1850 .sidle_shift = 24,
1851 .clkact_shift = -ENODEV,
1852 .enwkup_shift = 26,
1853 .srst_shift = -ENODEV,
1854 .emufree_shift = -ENODEV,
1855 .autoidle_shift = -ENODEV,
1856};
1857
1858static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
1859 .type = TI_SYSC_OMAP4_USB_HOST_FS,
1860 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
1861 .regbits = &sysc_regbits_omap4_usb_host_fs,
1862};
1863
Faiz Abbas7f35e632018-07-09 22:18:38 +05301864static const struct sysc_regbits sysc_regbits_dra7_mcan = {
1865 .dmadisable_shift = -ENODEV,
1866 .midle_shift = -ENODEV,
1867 .sidle_shift = -ENODEV,
1868 .clkact_shift = -ENODEV,
1869 .enwkup_shift = 4,
1870 .srst_shift = 0,
1871 .emufree_shift = -ENODEV,
1872 .autoidle_shift = -ENODEV,
1873};
1874
1875static const struct sysc_capabilities sysc_dra7_mcan = {
1876 .type = TI_SYSC_DRA7_MCAN,
1877 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
1878 .regbits = &sysc_regbits_dra7_mcan,
1879};
1880
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001881static int sysc_init_pdata(struct sysc *ddata)
1882{
1883 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001884 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001885
1886 if (!pdata || !ddata->legacy_mode)
1887 return 0;
1888
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001889 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
1890 if (!mdata)
1891 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001892
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001893 mdata->name = ddata->legacy_mode;
1894 mdata->module_pa = ddata->module_pa;
1895 mdata->module_size = ddata->module_size;
1896 mdata->offsets = ddata->offsets;
1897 mdata->nr_offsets = SYSC_MAX_REGS;
1898 mdata->cap = ddata->cap;
1899 mdata->cfg = &ddata->cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001900
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001901 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001902
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001903 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001904}
1905
Tony Lindgren70a65242017-12-15 09:41:09 -08001906static int sysc_init_match(struct sysc *ddata)
1907{
1908 const struct sysc_capabilities *cap;
1909
1910 cap = of_device_get_match_data(ddata->dev);
1911 if (!cap)
1912 return -EINVAL;
1913
1914 ddata->cap = cap;
1915 if (ddata->cap)
1916 ddata->cfg.quirks |= ddata->cap->mod_quirks;
1917
1918 return 0;
1919}
1920
Tony Lindgren76f0f772018-02-23 08:28:45 -08001921static void ti_sysc_idle(struct work_struct *work)
1922{
1923 struct sysc *ddata;
1924
1925 ddata = container_of(work, struct sysc, idle_work.work);
1926
1927 if (pm_runtime_active(ddata->dev))
1928 pm_runtime_put_sync(ddata->dev);
1929}
1930
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07001931static const struct of_device_id sysc_match_table[] = {
1932 { .compatible = "simple-bus", },
1933 { /* sentinel */ },
1934};
1935
Tony Lindgren0eecc632017-10-10 14:23:43 -07001936static int sysc_probe(struct platform_device *pdev)
1937{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001938 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001939 struct sysc *ddata;
1940 int error;
1941
1942 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
1943 if (!ddata)
1944 return -ENOMEM;
1945
1946 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001947 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001948
Tony Lindgren70a65242017-12-15 09:41:09 -08001949 error = sysc_init_match(ddata);
1950 if (error)
1951 return error;
1952
Tony Lindgren566a9b052017-12-15 09:41:19 -08001953 error = sysc_init_dts_quirks(ddata);
1954 if (error)
1955 goto unprepare;
1956
Tony Lindgren0eecc632017-10-10 14:23:43 -07001957 error = sysc_map_and_check_registers(ddata);
1958 if (error)
1959 goto unprepare;
1960
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001961 error = sysc_init_sysc_mask(ddata);
1962 if (error)
1963 goto unprepare;
1964
1965 error = sysc_init_idlemodes(ddata);
1966 if (error)
1967 goto unprepare;
1968
1969 error = sysc_init_syss_mask(ddata);
1970 if (error)
1971 goto unprepare;
1972
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001973 error = sysc_init_pdata(ddata);
1974 if (error)
1975 goto unprepare;
1976
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001977 sysc_init_early_quirks(ddata);
1978
1979 error = sysc_get_clocks(ddata);
1980 if (error)
1981 return error;
1982
Tony Lindgren50622362018-04-16 10:20:27 -07001983 error = sysc_init_resets(ddata);
1984 if (error)
1985 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001986
1987 error = sysc_init_module(ddata);
1988 if (error)
1989 goto unprepare;
1990
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001991 pm_runtime_enable(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001992 error = pm_runtime_get_sync(ddata->dev);
1993 if (error < 0) {
1994 pm_runtime_put_noidle(ddata->dev);
1995 pm_runtime_disable(ddata->dev);
1996 goto unprepare;
1997 }
1998
Tony Lindgren0eecc632017-10-10 14:23:43 -07001999 sysc_show_registers(ddata);
2000
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002001 ddata->dev->type = &sysc_device_type;
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002002 error = of_platform_populate(ddata->dev->of_node, sysc_match_table,
2003 pdata ? pdata->auxdata : NULL,
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002004 ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002005 if (error)
2006 goto err;
2007
Tony Lindgren76f0f772018-02-23 08:28:45 -08002008 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
2009
2010 /* At least earlycon won't survive without deferred idle */
2011 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE_ON_INIT |
2012 SYSC_QUIRK_NO_RESET_ON_INIT)) {
2013 schedule_delayed_work(&ddata->idle_work, 3000);
2014 } else {
2015 pm_runtime_put(&pdev->dev);
2016 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07002017
Tony Lindgren50622362018-04-16 10:20:27 -07002018 if (!of_get_available_child_count(ddata->dev->of_node))
2019 reset_control_assert(ddata->rsts);
2020
Tony Lindgren0eecc632017-10-10 14:23:43 -07002021 return 0;
2022
2023err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07002024 pm_runtime_put_sync(&pdev->dev);
2025 pm_runtime_disable(&pdev->dev);
2026unprepare:
2027 sysc_unprepare(ddata);
2028
2029 return error;
2030}
2031
Tony Lindgren684be5a2017-10-13 10:48:40 -07002032static int sysc_remove(struct platform_device *pdev)
2033{
2034 struct sysc *ddata = platform_get_drvdata(pdev);
2035 int error;
2036
Tony Lindgren76f0f772018-02-23 08:28:45 -08002037 cancel_delayed_work_sync(&ddata->idle_work);
2038
Tony Lindgren684be5a2017-10-13 10:48:40 -07002039 error = pm_runtime_get_sync(ddata->dev);
2040 if (error < 0) {
2041 pm_runtime_put_noidle(ddata->dev);
2042 pm_runtime_disable(ddata->dev);
2043 goto unprepare;
2044 }
2045
2046 of_platform_depopulate(&pdev->dev);
2047
Tony Lindgren684be5a2017-10-13 10:48:40 -07002048 pm_runtime_put_sync(&pdev->dev);
2049 pm_runtime_disable(&pdev->dev);
Tony Lindgren50622362018-04-16 10:20:27 -07002050 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07002051
2052unprepare:
2053 sysc_unprepare(ddata);
2054
2055 return 0;
2056}
2057
Tony Lindgren0eecc632017-10-10 14:23:43 -07002058static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08002059 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
2060 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
2061 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
2062 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
2063 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
2064 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
2065 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
2066 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
2067 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
2068 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
2069 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08002070 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08002071 { .compatible = "ti,sysc-usb-host-fs",
2072 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05302073 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07002074 { },
2075};
2076MODULE_DEVICE_TABLE(of, sysc_match);
2077
2078static struct platform_driver sysc_driver = {
2079 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07002080 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07002081 .driver = {
2082 .name = "ti-sysc",
2083 .of_match_table = sysc_match,
2084 .pm = &sysc_pm_ops,
2085 },
2086};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002087
2088static int __init sysc_init(void)
2089{
2090 bus_register_notifier(&platform_bus_type, &sysc_nb);
2091
2092 return platform_driver_register(&sysc_driver);
2093}
2094module_init(sysc_init);
2095
2096static void __exit sysc_exit(void)
2097{
2098 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
2099 platform_driver_unregister(&sysc_driver);
2100}
2101module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002102
2103MODULE_DESCRIPTION("TI sysc interconnect target driver");
2104MODULE_LICENSE("GPL v2");