blob: 0c9b9bcd75b27055ba79f6a1186daef21c2a99b3 [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>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/pm_runtime.h>
19#include <linux/of_address.h>
20#include <linux/of_platform.h>
Tony Lindgren70a65242017-12-15 09:41:09 -080021#include <linux/platform_data/ti-sysc.h>
22
23#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070024
25enum sysc_registers {
26 SYSC_REVISION,
27 SYSC_SYSCONFIG,
28 SYSC_SYSSTATUS,
29 SYSC_MAX_REGS,
30};
31
32static const char * const reg_names[] = { "rev", "sysc", "syss", };
33
34enum sysc_clocks {
35 SYSC_FCK,
36 SYSC_ICK,
37 SYSC_MAX_CLOCKS,
38};
39
40static const char * const clock_names[] = { "fck", "ick", };
41
42/**
43 * struct sysc - TI sysc interconnect target module registers and capabilities
44 * @dev: struct device pointer
45 * @module_pa: physical address of the interconnect target module
46 * @module_size: size of the interconnect target module
47 * @module_va: virtual address of the interconnect target module
48 * @offsets: register offsets from module base
49 * @clocks: clocks used by the interconnect target module
50 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -080051 * @cap: interconnect target module capabilities
52 * @cfg: interconnect target module configuration
Tony Lindgren0eecc632017-10-10 14:23:43 -070053 */
54struct sysc {
55 struct device *dev;
56 u64 module_pa;
57 u32 module_size;
58 void __iomem *module_va;
59 int offsets[SYSC_MAX_REGS];
60 struct clk *clocks[SYSC_MAX_CLOCKS];
61 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -080062 const struct sysc_capabilities *cap;
63 struct sysc_config cfg;
Tony Lindgren0eecc632017-10-10 14:23:43 -070064};
65
66static u32 sysc_read_revision(struct sysc *ddata)
67{
68 return readl_relaxed(ddata->module_va +
69 ddata->offsets[SYSC_REVISION]);
70}
71
72static int sysc_get_one_clock(struct sysc *ddata,
73 enum sysc_clocks index)
74{
75 const char *name;
76 int error;
77
78 switch (index) {
79 case SYSC_FCK:
80 break;
81 case SYSC_ICK:
82 break;
83 default:
84 return -EINVAL;
85 }
86 name = clock_names[index];
87
88 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
89 if (IS_ERR(ddata->clocks[index])) {
90 if (PTR_ERR(ddata->clocks[index]) == -ENOENT)
91 return 0;
92
93 dev_err(ddata->dev, "clock get error for %s: %li\n",
94 name, PTR_ERR(ddata->clocks[index]));
95
96 return PTR_ERR(ddata->clocks[index]);
97 }
98
99 error = clk_prepare(ddata->clocks[index]);
100 if (error) {
101 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
102 name, error);
103
104 return error;
105 }
106
107 return 0;
108}
109
110static int sysc_get_clocks(struct sysc *ddata)
111{
112 int i, error;
113
114 if (ddata->legacy_mode)
115 return 0;
116
117 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
118 error = sysc_get_one_clock(ddata, i);
119 if (error && error != -ENOENT)
120 return error;
121 }
122
123 return 0;
124}
125
126/**
127 * sysc_parse_and_check_child_range - parses module IO region from ranges
128 * @ddata: device driver data
129 *
130 * In general we only need rev, syss, and sysc registers and not the whole
131 * module range. But we do want the offsets for these registers from the
132 * module base. This allows us to check them against the legacy hwmod
133 * platform data. Let's also check the ranges are configured properly.
134 */
135static int sysc_parse_and_check_child_range(struct sysc *ddata)
136{
137 struct device_node *np = ddata->dev->of_node;
138 const __be32 *ranges;
139 u32 nr_addr, nr_size;
140 int len, error;
141
142 ranges = of_get_property(np, "ranges", &len);
143 if (!ranges) {
144 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
145
146 return -ENOENT;
147 }
148
149 len /= sizeof(*ranges);
150
151 if (len < 3) {
152 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
153
154 return -EINVAL;
155 }
156
157 error = of_property_read_u32(np, "#address-cells", &nr_addr);
158 if (error)
159 return -ENOENT;
160
161 error = of_property_read_u32(np, "#size-cells", &nr_size);
162 if (error)
163 return -ENOENT;
164
165 if (nr_addr != 1 || nr_size != 1) {
166 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
167
168 return -EINVAL;
169 }
170
171 ranges++;
172 ddata->module_pa = of_translate_address(np, ranges++);
173 ddata->module_size = be32_to_cpup(ranges);
174
175 dev_dbg(ddata->dev, "interconnect target 0x%llx size 0x%x for %pOF\n",
176 ddata->module_pa, ddata->module_size, np);
177
178 return 0;
179}
180
181/**
182 * sysc_check_one_child - check child configuration
183 * @ddata: device driver data
184 * @np: child device node
185 *
186 * Let's avoid messy situations where we have new interconnect target
187 * node but children have "ti,hwmods". These belong to the interconnect
188 * target node and are managed by this driver.
189 */
190static int sysc_check_one_child(struct sysc *ddata,
191 struct device_node *np)
192{
193 const char *name;
194
195 name = of_get_property(np, "ti,hwmods", NULL);
196 if (name)
197 dev_warn(ddata->dev, "really a child ti,hwmods property?");
198
199 return 0;
200}
201
202static int sysc_check_children(struct sysc *ddata)
203{
204 struct device_node *child;
205 int error;
206
207 for_each_child_of_node(ddata->dev->of_node, child) {
208 error = sysc_check_one_child(ddata, child);
209 if (error)
210 return error;
211 }
212
213 return 0;
214}
215
216/**
217 * sysc_parse_one - parses the interconnect target module registers
218 * @ddata: device driver data
219 * @reg: register to parse
220 */
221static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
222{
223 struct resource *res;
224 const char *name;
225
226 switch (reg) {
227 case SYSC_REVISION:
228 case SYSC_SYSCONFIG:
229 case SYSC_SYSSTATUS:
230 name = reg_names[reg];
231 break;
232 default:
233 return -EINVAL;
234 }
235
236 res = platform_get_resource_byname(to_platform_device(ddata->dev),
237 IORESOURCE_MEM, name);
238 if (!res) {
239 dev_dbg(ddata->dev, "has no %s register\n", name);
240 ddata->offsets[reg] = -ENODEV;
241
242 return 0;
243 }
244
245 ddata->offsets[reg] = res->start - ddata->module_pa;
246
247 return 0;
248}
249
250static int sysc_parse_registers(struct sysc *ddata)
251{
252 int i, error;
253
254 for (i = 0; i < SYSC_MAX_REGS; i++) {
255 error = sysc_parse_one(ddata, i);
256 if (error)
257 return error;
258 }
259
260 return 0;
261}
262
263/**
264 * sysc_check_registers - check for misconfigured register overlaps
265 * @ddata: device driver data
266 */
267static int sysc_check_registers(struct sysc *ddata)
268{
269 int i, j, nr_regs = 0, nr_matches = 0;
270
271 for (i = 0; i < SYSC_MAX_REGS; i++) {
272 if (ddata->offsets[i] < 0)
273 continue;
274
275 if (ddata->offsets[i] > (ddata->module_size - 4)) {
276 dev_err(ddata->dev, "register outside module range");
277
278 return -EINVAL;
279 }
280
281 for (j = 0; j < SYSC_MAX_REGS; j++) {
282 if (ddata->offsets[j] < 0)
283 continue;
284
285 if (ddata->offsets[i] == ddata->offsets[j])
286 nr_matches++;
287 }
288 nr_regs++;
289 }
290
291 if (nr_regs < 1) {
292 dev_err(ddata->dev, "missing registers\n");
293
294 return -EINVAL;
295 }
296
297 if (nr_matches > nr_regs) {
298 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
299 nr_regs, nr_matches);
300
301 return -EINVAL;
302 }
303
304 return 0;
305}
306
307/**
308 * syc_ioremap - ioremap register space for the interconnect target module
309 * @ddata: deviec driver data
310 *
311 * Note that the interconnect target module registers can be anywhere
312 * within the first child device address space. For example, SGX has
313 * them at offset 0x1fc00 in the 32MB module address space. We just
314 * what we need around the interconnect target module registers.
315 */
316static int sysc_ioremap(struct sysc *ddata)
317{
318 u32 size = 0;
319
320 if (ddata->offsets[SYSC_SYSSTATUS] >= 0)
321 size = ddata->offsets[SYSC_SYSSTATUS];
322 else if (ddata->offsets[SYSC_SYSCONFIG] >= 0)
323 size = ddata->offsets[SYSC_SYSCONFIG];
324 else if (ddata->offsets[SYSC_REVISION] >= 0)
325 size = ddata->offsets[SYSC_REVISION];
326 else
327 return -EINVAL;
328
329 size &= 0xfff00;
330 size += SZ_256;
331
332 ddata->module_va = devm_ioremap(ddata->dev,
333 ddata->module_pa,
334 size);
335 if (!ddata->module_va)
336 return -EIO;
337
338 return 0;
339}
340
341/**
342 * sysc_map_and_check_registers - ioremap and check device registers
343 * @ddata: device driver data
344 */
345static int sysc_map_and_check_registers(struct sysc *ddata)
346{
347 int error;
348
349 error = sysc_parse_and_check_child_range(ddata);
350 if (error)
351 return error;
352
353 error = sysc_check_children(ddata);
354 if (error)
355 return error;
356
357 error = sysc_parse_registers(ddata);
358 if (error)
359 return error;
360
361 error = sysc_ioremap(ddata);
362 if (error)
363 return error;
364
365 error = sysc_check_registers(ddata);
366 if (error)
367 return error;
368
369 return 0;
370}
371
372/**
373 * sysc_show_rev - read and show interconnect target module revision
374 * @bufp: buffer to print the information to
375 * @ddata: device driver data
376 */
377static int sysc_show_rev(char *bufp, struct sysc *ddata)
378{
379 int error, len;
380
381 if (ddata->offsets[SYSC_REVISION] < 0)
382 return sprintf(bufp, ":NA");
383
384 error = pm_runtime_get_sync(ddata->dev);
385 if (error < 0) {
386 pm_runtime_put_noidle(ddata->dev);
387
388 return 0;
389 }
390
391 len = sprintf(bufp, ":%08x", sysc_read_revision(ddata));
392
393 pm_runtime_mark_last_busy(ddata->dev);
394 pm_runtime_put_autosuspend(ddata->dev);
395
396 return len;
397}
398
399static int sysc_show_reg(struct sysc *ddata,
400 char *bufp, enum sysc_registers reg)
401{
402 if (ddata->offsets[reg] < 0)
403 return sprintf(bufp, ":NA");
404
405 return sprintf(bufp, ":%x", ddata->offsets[reg]);
406}
407
408/**
409 * sysc_show_registers - show information about interconnect target module
410 * @ddata: device driver data
411 */
412static void sysc_show_registers(struct sysc *ddata)
413{
414 char buf[128];
415 char *bufp = buf;
416 int i;
417
418 for (i = 0; i < SYSC_MAX_REGS; i++)
419 bufp += sysc_show_reg(ddata, bufp, i);
420
421 bufp += sysc_show_rev(bufp, ddata);
422
423 dev_dbg(ddata->dev, "%llx:%x%s\n",
424 ddata->module_pa, ddata->module_size,
425 buf);
426}
427
Arnd Bergmanna4a5d492017-10-13 11:25:32 +0200428static int __maybe_unused sysc_runtime_suspend(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700429{
430 struct sysc *ddata;
431 int i;
432
433 ddata = dev_get_drvdata(dev);
434
435 if (ddata->legacy_mode)
436 return 0;
437
438 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
439 if (IS_ERR_OR_NULL(ddata->clocks[i]))
440 continue;
441 clk_disable(ddata->clocks[i]);
442 }
443
444 return 0;
445}
446
Arnd Bergmanna4a5d492017-10-13 11:25:32 +0200447static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700448{
449 struct sysc *ddata;
450 int i, error;
451
452 ddata = dev_get_drvdata(dev);
453
454 if (ddata->legacy_mode)
455 return 0;
456
457 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
458 if (IS_ERR_OR_NULL(ddata->clocks[i]))
459 continue;
460 error = clk_enable(ddata->clocks[i]);
461 if (error)
462 return error;
463 }
464
465 return 0;
466}
467
468static const struct dev_pm_ops sysc_pm_ops = {
469 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
470 sysc_runtime_resume,
471 NULL)
472};
473
474static void sysc_unprepare(struct sysc *ddata)
475{
476 int i;
477
478 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
479 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
480 clk_unprepare(ddata->clocks[i]);
481 }
482}
483
Tony Lindgren70a65242017-12-15 09:41:09 -0800484/*
485 * Common sysc register bits found on omap2, also known as type1
486 */
487static const struct sysc_regbits sysc_regbits_omap2 = {
488 .dmadisable_shift = -ENODEV,
489 .midle_shift = 12,
490 .sidle_shift = 3,
491 .clkact_shift = 8,
492 .emufree_shift = 5,
493 .enwkup_shift = 2,
494 .srst_shift = 1,
495 .autoidle_shift = 0,
496};
497
498static const struct sysc_capabilities sysc_omap2 = {
499 .type = TI_SYSC_OMAP2,
500 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
501 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
502 SYSC_OMAP2_AUTOIDLE,
503 .regbits = &sysc_regbits_omap2,
504};
505
506/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
507static const struct sysc_capabilities sysc_omap2_timer = {
508 .type = TI_SYSC_OMAP2_TIMER,
509 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
510 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
511 SYSC_OMAP2_AUTOIDLE,
512 .regbits = &sysc_regbits_omap2,
513 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
514};
515
516/*
517 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
518 * with different sidle position
519 */
520static const struct sysc_regbits sysc_regbits_omap3_sham = {
521 .dmadisable_shift = -ENODEV,
522 .midle_shift = -ENODEV,
523 .sidle_shift = 4,
524 .clkact_shift = -ENODEV,
525 .enwkup_shift = -ENODEV,
526 .srst_shift = 1,
527 .autoidle_shift = 0,
528 .emufree_shift = -ENODEV,
529};
530
531static const struct sysc_capabilities sysc_omap3_sham = {
532 .type = TI_SYSC_OMAP3_SHAM,
533 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
534 .regbits = &sysc_regbits_omap3_sham,
535};
536
537/*
538 * AES register bits found on omap3 and later, a variant of
539 * sysc_regbits_omap2 with different sidle position
540 */
541static const struct sysc_regbits sysc_regbits_omap3_aes = {
542 .dmadisable_shift = -ENODEV,
543 .midle_shift = -ENODEV,
544 .sidle_shift = 6,
545 .clkact_shift = -ENODEV,
546 .enwkup_shift = -ENODEV,
547 .srst_shift = 1,
548 .autoidle_shift = 0,
549 .emufree_shift = -ENODEV,
550};
551
552static const struct sysc_capabilities sysc_omap3_aes = {
553 .type = TI_SYSC_OMAP3_AES,
554 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
555 .regbits = &sysc_regbits_omap3_aes,
556};
557
558/*
559 * Common sysc register bits found on omap4, also known as type2
560 */
561static const struct sysc_regbits sysc_regbits_omap4 = {
562 .dmadisable_shift = 16,
563 .midle_shift = 4,
564 .sidle_shift = 2,
565 .clkact_shift = -ENODEV,
566 .enwkup_shift = -ENODEV,
567 .emufree_shift = 1,
568 .srst_shift = 0,
569 .autoidle_shift = -ENODEV,
570};
571
572static const struct sysc_capabilities sysc_omap4 = {
573 .type = TI_SYSC_OMAP4,
574 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
575 SYSC_OMAP4_SOFTRESET,
576 .regbits = &sysc_regbits_omap4,
577};
578
579static const struct sysc_capabilities sysc_omap4_timer = {
580 .type = TI_SYSC_OMAP4_TIMER,
581 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
582 SYSC_OMAP4_SOFTRESET,
583 .regbits = &sysc_regbits_omap4,
584};
585
586/*
587 * Common sysc register bits found on omap4, also known as type3
588 */
589static const struct sysc_regbits sysc_regbits_omap4_simple = {
590 .dmadisable_shift = -ENODEV,
591 .midle_shift = 2,
592 .sidle_shift = 0,
593 .clkact_shift = -ENODEV,
594 .enwkup_shift = -ENODEV,
595 .srst_shift = -ENODEV,
596 .emufree_shift = -ENODEV,
597 .autoidle_shift = -ENODEV,
598};
599
600static const struct sysc_capabilities sysc_omap4_simple = {
601 .type = TI_SYSC_OMAP4_SIMPLE,
602 .regbits = &sysc_regbits_omap4_simple,
603};
604
605/*
606 * SmartReflex sysc found on omap34xx
607 */
608static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
609 .dmadisable_shift = -ENODEV,
610 .midle_shift = -ENODEV,
611 .sidle_shift = -ENODEV,
612 .clkact_shift = 20,
613 .enwkup_shift = -ENODEV,
614 .srst_shift = -ENODEV,
615 .emufree_shift = -ENODEV,
616 .autoidle_shift = -ENODEV,
617};
618
619static const struct sysc_capabilities sysc_34xx_sr = {
620 .type = TI_SYSC_OMAP34XX_SR,
621 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
622 .regbits = &sysc_regbits_omap34xx_sr,
623 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED,
624};
625
626/*
627 * SmartReflex sysc found on omap36xx and later
628 */
629static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
630 .dmadisable_shift = -ENODEV,
631 .midle_shift = -ENODEV,
632 .sidle_shift = 24,
633 .clkact_shift = -ENODEV,
634 .enwkup_shift = 26,
635 .srst_shift = -ENODEV,
636 .emufree_shift = -ENODEV,
637 .autoidle_shift = -ENODEV,
638};
639
640static const struct sysc_capabilities sysc_36xx_sr = {
641 .type = TI_SYSC_OMAP36XX_SR,
642 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
643 .regbits = &sysc_regbits_omap36xx_sr,
644 .mod_quirks = SYSC_QUIRK_UNCACHED,
645};
646
647static const struct sysc_capabilities sysc_omap4_sr = {
648 .type = TI_SYSC_OMAP4_SR,
649 .regbits = &sysc_regbits_omap36xx_sr,
650};
651
652/*
653 * McASP register bits found on omap4 and later
654 */
655static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
656 .dmadisable_shift = -ENODEV,
657 .midle_shift = -ENODEV,
658 .sidle_shift = 0,
659 .clkact_shift = -ENODEV,
660 .enwkup_shift = -ENODEV,
661 .srst_shift = -ENODEV,
662 .emufree_shift = -ENODEV,
663 .autoidle_shift = -ENODEV,
664};
665
666static const struct sysc_capabilities sysc_omap4_mcasp = {
667 .type = TI_SYSC_OMAP4_MCASP,
668 .regbits = &sysc_regbits_omap4_mcasp,
669};
670
671/*
672 * FS USB host found on omap4 and later
673 */
674static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
675 .dmadisable_shift = -ENODEV,
676 .midle_shift = -ENODEV,
677 .sidle_shift = 24,
678 .clkact_shift = -ENODEV,
679 .enwkup_shift = 26,
680 .srst_shift = -ENODEV,
681 .emufree_shift = -ENODEV,
682 .autoidle_shift = -ENODEV,
683};
684
685static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
686 .type = TI_SYSC_OMAP4_USB_HOST_FS,
687 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
688 .regbits = &sysc_regbits_omap4_usb_host_fs,
689};
690
691static int sysc_init_match(struct sysc *ddata)
692{
693 const struct sysc_capabilities *cap;
694
695 cap = of_device_get_match_data(ddata->dev);
696 if (!cap)
697 return -EINVAL;
698
699 ddata->cap = cap;
700 if (ddata->cap)
701 ddata->cfg.quirks |= ddata->cap->mod_quirks;
702
703 return 0;
704}
705
Tony Lindgren0eecc632017-10-10 14:23:43 -0700706static int sysc_probe(struct platform_device *pdev)
707{
708 struct device_node *np = pdev->dev.of_node;
709 struct sysc *ddata;
710 int error;
711
712 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
713 if (!ddata)
714 return -ENOMEM;
715
716 ddata->dev = &pdev->dev;
717 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
718
Tony Lindgren70a65242017-12-15 09:41:09 -0800719 error = sysc_init_match(ddata);
720 if (error)
721 return error;
722
Tony Lindgren0eecc632017-10-10 14:23:43 -0700723 error = sysc_get_clocks(ddata);
724 if (error)
725 return error;
726
727 error = sysc_map_and_check_registers(ddata);
728 if (error)
729 goto unprepare;
730
731 platform_set_drvdata(pdev, ddata);
732
733 pm_runtime_enable(ddata->dev);
734 error = pm_runtime_get_sync(ddata->dev);
735 if (error < 0) {
736 pm_runtime_put_noidle(ddata->dev);
737 pm_runtime_disable(ddata->dev);
738 goto unprepare;
739 }
740
741 pm_runtime_use_autosuspend(ddata->dev);
742
743 sysc_show_registers(ddata);
744
745 error = of_platform_populate(ddata->dev->of_node,
746 NULL, NULL, ddata->dev);
747 if (error)
748 goto err;
749
750 pm_runtime_mark_last_busy(ddata->dev);
751 pm_runtime_put_autosuspend(ddata->dev);
752
753 return 0;
754
755err:
756 pm_runtime_dont_use_autosuspend(&pdev->dev);
757 pm_runtime_put_sync(&pdev->dev);
758 pm_runtime_disable(&pdev->dev);
759unprepare:
760 sysc_unprepare(ddata);
761
762 return error;
763}
764
Tony Lindgren684be5a2017-10-13 10:48:40 -0700765static int sysc_remove(struct platform_device *pdev)
766{
767 struct sysc *ddata = platform_get_drvdata(pdev);
768 int error;
769
770 error = pm_runtime_get_sync(ddata->dev);
771 if (error < 0) {
772 pm_runtime_put_noidle(ddata->dev);
773 pm_runtime_disable(ddata->dev);
774 goto unprepare;
775 }
776
777 of_platform_depopulate(&pdev->dev);
778
779 pm_runtime_dont_use_autosuspend(&pdev->dev);
780 pm_runtime_put_sync(&pdev->dev);
781 pm_runtime_disable(&pdev->dev);
782
783unprepare:
784 sysc_unprepare(ddata);
785
786 return 0;
787}
788
Tony Lindgren0eecc632017-10-10 14:23:43 -0700789static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -0800790 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
791 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
792 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
793 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
794 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
795 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
796 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
797 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
798 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
799 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
800 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
801 { .compatible = "ti,sysc-usb-host-fs",
802 .data = &sysc_omap4_usb_host_fs, },
Tony Lindgren0eecc632017-10-10 14:23:43 -0700803 { },
804};
805MODULE_DEVICE_TABLE(of, sysc_match);
806
807static struct platform_driver sysc_driver = {
808 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -0700809 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -0700810 .driver = {
811 .name = "ti-sysc",
812 .of_match_table = sysc_match,
813 .pm = &sysc_pm_ops,
814 },
815};
816module_platform_driver(sysc_driver);
817
818MODULE_DESCRIPTION("TI sysc interconnect target driver");
819MODULE_LICENSE("GPL v2");