blob: 4c1e59e53a0c785bd568df6d2ee9010736e3522f [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
Tony Lindgrena7199e22017-12-15 09:41:14 -0800216/*
217 * So far only I2C uses 16-bit read access with clockactivity with revision
218 * in two registers with stride of 4. We can detect this based on the rev
219 * register size to configure things far enough to be able to properly read
220 * the revision register.
221 */
222static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
223{
224 if (resource_size(res) == 8) {
225 dev_dbg(ddata->dev,
226 "enabling 16-bit and clockactivity quirks\n");
227 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
228 }
229}
230
Tony Lindgren0eecc632017-10-10 14:23:43 -0700231/**
232 * sysc_parse_one - parses the interconnect target module registers
233 * @ddata: device driver data
234 * @reg: register to parse
235 */
236static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
237{
238 struct resource *res;
239 const char *name;
240
241 switch (reg) {
242 case SYSC_REVISION:
243 case SYSC_SYSCONFIG:
244 case SYSC_SYSSTATUS:
245 name = reg_names[reg];
246 break;
247 default:
248 return -EINVAL;
249 }
250
251 res = platform_get_resource_byname(to_platform_device(ddata->dev),
252 IORESOURCE_MEM, name);
253 if (!res) {
254 dev_dbg(ddata->dev, "has no %s register\n", name);
255 ddata->offsets[reg] = -ENODEV;
256
257 return 0;
258 }
259
260 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800261 if (reg == SYSC_REVISION)
262 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700263
264 return 0;
265}
266
267static int sysc_parse_registers(struct sysc *ddata)
268{
269 int i, error;
270
271 for (i = 0; i < SYSC_MAX_REGS; i++) {
272 error = sysc_parse_one(ddata, i);
273 if (error)
274 return error;
275 }
276
277 return 0;
278}
279
280/**
281 * sysc_check_registers - check for misconfigured register overlaps
282 * @ddata: device driver data
283 */
284static int sysc_check_registers(struct sysc *ddata)
285{
286 int i, j, nr_regs = 0, nr_matches = 0;
287
288 for (i = 0; i < SYSC_MAX_REGS; i++) {
289 if (ddata->offsets[i] < 0)
290 continue;
291
292 if (ddata->offsets[i] > (ddata->module_size - 4)) {
293 dev_err(ddata->dev, "register outside module range");
294
295 return -EINVAL;
296 }
297
298 for (j = 0; j < SYSC_MAX_REGS; j++) {
299 if (ddata->offsets[j] < 0)
300 continue;
301
302 if (ddata->offsets[i] == ddata->offsets[j])
303 nr_matches++;
304 }
305 nr_regs++;
306 }
307
308 if (nr_regs < 1) {
309 dev_err(ddata->dev, "missing registers\n");
310
311 return -EINVAL;
312 }
313
314 if (nr_matches > nr_regs) {
315 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
316 nr_regs, nr_matches);
317
318 return -EINVAL;
319 }
320
321 return 0;
322}
323
324/**
325 * syc_ioremap - ioremap register space for the interconnect target module
326 * @ddata: deviec driver data
327 *
328 * Note that the interconnect target module registers can be anywhere
329 * within the first child device address space. For example, SGX has
330 * them at offset 0x1fc00 in the 32MB module address space. We just
331 * what we need around the interconnect target module registers.
332 */
333static int sysc_ioremap(struct sysc *ddata)
334{
335 u32 size = 0;
336
337 if (ddata->offsets[SYSC_SYSSTATUS] >= 0)
338 size = ddata->offsets[SYSC_SYSSTATUS];
339 else if (ddata->offsets[SYSC_SYSCONFIG] >= 0)
340 size = ddata->offsets[SYSC_SYSCONFIG];
341 else if (ddata->offsets[SYSC_REVISION] >= 0)
342 size = ddata->offsets[SYSC_REVISION];
343 else
344 return -EINVAL;
345
346 size &= 0xfff00;
347 size += SZ_256;
348
349 ddata->module_va = devm_ioremap(ddata->dev,
350 ddata->module_pa,
351 size);
352 if (!ddata->module_va)
353 return -EIO;
354
355 return 0;
356}
357
358/**
359 * sysc_map_and_check_registers - ioremap and check device registers
360 * @ddata: device driver data
361 */
362static int sysc_map_and_check_registers(struct sysc *ddata)
363{
364 int error;
365
366 error = sysc_parse_and_check_child_range(ddata);
367 if (error)
368 return error;
369
370 error = sysc_check_children(ddata);
371 if (error)
372 return error;
373
374 error = sysc_parse_registers(ddata);
375 if (error)
376 return error;
377
378 error = sysc_ioremap(ddata);
379 if (error)
380 return error;
381
382 error = sysc_check_registers(ddata);
383 if (error)
384 return error;
385
386 return 0;
387}
388
389/**
390 * sysc_show_rev - read and show interconnect target module revision
391 * @bufp: buffer to print the information to
392 * @ddata: device driver data
393 */
394static int sysc_show_rev(char *bufp, struct sysc *ddata)
395{
396 int error, len;
397
398 if (ddata->offsets[SYSC_REVISION] < 0)
399 return sprintf(bufp, ":NA");
400
401 error = pm_runtime_get_sync(ddata->dev);
402 if (error < 0) {
403 pm_runtime_put_noidle(ddata->dev);
404
405 return 0;
406 }
407
408 len = sprintf(bufp, ":%08x", sysc_read_revision(ddata));
409
410 pm_runtime_mark_last_busy(ddata->dev);
411 pm_runtime_put_autosuspend(ddata->dev);
412
413 return len;
414}
415
416static int sysc_show_reg(struct sysc *ddata,
417 char *bufp, enum sysc_registers reg)
418{
419 if (ddata->offsets[reg] < 0)
420 return sprintf(bufp, ":NA");
421
422 return sprintf(bufp, ":%x", ddata->offsets[reg]);
423}
424
425/**
426 * sysc_show_registers - show information about interconnect target module
427 * @ddata: device driver data
428 */
429static void sysc_show_registers(struct sysc *ddata)
430{
431 char buf[128];
432 char *bufp = buf;
433 int i;
434
435 for (i = 0; i < SYSC_MAX_REGS; i++)
436 bufp += sysc_show_reg(ddata, bufp, i);
437
438 bufp += sysc_show_rev(bufp, ddata);
439
440 dev_dbg(ddata->dev, "%llx:%x%s\n",
441 ddata->module_pa, ddata->module_size,
442 buf);
443}
444
Arnd Bergmanna4a5d492017-10-13 11:25:32 +0200445static int __maybe_unused sysc_runtime_suspend(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700446{
447 struct sysc *ddata;
448 int i;
449
450 ddata = dev_get_drvdata(dev);
451
452 if (ddata->legacy_mode)
453 return 0;
454
455 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
456 if (IS_ERR_OR_NULL(ddata->clocks[i]))
457 continue;
458 clk_disable(ddata->clocks[i]);
459 }
460
461 return 0;
462}
463
Arnd Bergmanna4a5d492017-10-13 11:25:32 +0200464static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700465{
466 struct sysc *ddata;
467 int i, error;
468
469 ddata = dev_get_drvdata(dev);
470
471 if (ddata->legacy_mode)
472 return 0;
473
474 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
475 if (IS_ERR_OR_NULL(ddata->clocks[i]))
476 continue;
477 error = clk_enable(ddata->clocks[i]);
478 if (error)
479 return error;
480 }
481
482 return 0;
483}
484
485static const struct dev_pm_ops sysc_pm_ops = {
486 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
487 sysc_runtime_resume,
488 NULL)
489};
490
491static void sysc_unprepare(struct sysc *ddata)
492{
493 int i;
494
495 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
496 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
497 clk_unprepare(ddata->clocks[i]);
498 }
499}
500
Tony Lindgren70a65242017-12-15 09:41:09 -0800501/*
502 * Common sysc register bits found on omap2, also known as type1
503 */
504static const struct sysc_regbits sysc_regbits_omap2 = {
505 .dmadisable_shift = -ENODEV,
506 .midle_shift = 12,
507 .sidle_shift = 3,
508 .clkact_shift = 8,
509 .emufree_shift = 5,
510 .enwkup_shift = 2,
511 .srst_shift = 1,
512 .autoidle_shift = 0,
513};
514
515static const struct sysc_capabilities sysc_omap2 = {
516 .type = TI_SYSC_OMAP2,
517 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
518 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
519 SYSC_OMAP2_AUTOIDLE,
520 .regbits = &sysc_regbits_omap2,
521};
522
523/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
524static const struct sysc_capabilities sysc_omap2_timer = {
525 .type = TI_SYSC_OMAP2_TIMER,
526 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
527 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
528 SYSC_OMAP2_AUTOIDLE,
529 .regbits = &sysc_regbits_omap2,
530 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
531};
532
533/*
534 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
535 * with different sidle position
536 */
537static const struct sysc_regbits sysc_regbits_omap3_sham = {
538 .dmadisable_shift = -ENODEV,
539 .midle_shift = -ENODEV,
540 .sidle_shift = 4,
541 .clkact_shift = -ENODEV,
542 .enwkup_shift = -ENODEV,
543 .srst_shift = 1,
544 .autoidle_shift = 0,
545 .emufree_shift = -ENODEV,
546};
547
548static const struct sysc_capabilities sysc_omap3_sham = {
549 .type = TI_SYSC_OMAP3_SHAM,
550 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
551 .regbits = &sysc_regbits_omap3_sham,
552};
553
554/*
555 * AES register bits found on omap3 and later, a variant of
556 * sysc_regbits_omap2 with different sidle position
557 */
558static const struct sysc_regbits sysc_regbits_omap3_aes = {
559 .dmadisable_shift = -ENODEV,
560 .midle_shift = -ENODEV,
561 .sidle_shift = 6,
562 .clkact_shift = -ENODEV,
563 .enwkup_shift = -ENODEV,
564 .srst_shift = 1,
565 .autoidle_shift = 0,
566 .emufree_shift = -ENODEV,
567};
568
569static const struct sysc_capabilities sysc_omap3_aes = {
570 .type = TI_SYSC_OMAP3_AES,
571 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
572 .regbits = &sysc_regbits_omap3_aes,
573};
574
575/*
576 * Common sysc register bits found on omap4, also known as type2
577 */
578static const struct sysc_regbits sysc_regbits_omap4 = {
579 .dmadisable_shift = 16,
580 .midle_shift = 4,
581 .sidle_shift = 2,
582 .clkact_shift = -ENODEV,
583 .enwkup_shift = -ENODEV,
584 .emufree_shift = 1,
585 .srst_shift = 0,
586 .autoidle_shift = -ENODEV,
587};
588
589static const struct sysc_capabilities sysc_omap4 = {
590 .type = TI_SYSC_OMAP4,
591 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
592 SYSC_OMAP4_SOFTRESET,
593 .regbits = &sysc_regbits_omap4,
594};
595
596static const struct sysc_capabilities sysc_omap4_timer = {
597 .type = TI_SYSC_OMAP4_TIMER,
598 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
599 SYSC_OMAP4_SOFTRESET,
600 .regbits = &sysc_regbits_omap4,
601};
602
603/*
604 * Common sysc register bits found on omap4, also known as type3
605 */
606static const struct sysc_regbits sysc_regbits_omap4_simple = {
607 .dmadisable_shift = -ENODEV,
608 .midle_shift = 2,
609 .sidle_shift = 0,
610 .clkact_shift = -ENODEV,
611 .enwkup_shift = -ENODEV,
612 .srst_shift = -ENODEV,
613 .emufree_shift = -ENODEV,
614 .autoidle_shift = -ENODEV,
615};
616
617static const struct sysc_capabilities sysc_omap4_simple = {
618 .type = TI_SYSC_OMAP4_SIMPLE,
619 .regbits = &sysc_regbits_omap4_simple,
620};
621
622/*
623 * SmartReflex sysc found on omap34xx
624 */
625static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
626 .dmadisable_shift = -ENODEV,
627 .midle_shift = -ENODEV,
628 .sidle_shift = -ENODEV,
629 .clkact_shift = 20,
630 .enwkup_shift = -ENODEV,
631 .srst_shift = -ENODEV,
632 .emufree_shift = -ENODEV,
633 .autoidle_shift = -ENODEV,
634};
635
636static const struct sysc_capabilities sysc_34xx_sr = {
637 .type = TI_SYSC_OMAP34XX_SR,
638 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
639 .regbits = &sysc_regbits_omap34xx_sr,
640 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED,
641};
642
643/*
644 * SmartReflex sysc found on omap36xx and later
645 */
646static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
647 .dmadisable_shift = -ENODEV,
648 .midle_shift = -ENODEV,
649 .sidle_shift = 24,
650 .clkact_shift = -ENODEV,
651 .enwkup_shift = 26,
652 .srst_shift = -ENODEV,
653 .emufree_shift = -ENODEV,
654 .autoidle_shift = -ENODEV,
655};
656
657static const struct sysc_capabilities sysc_36xx_sr = {
658 .type = TI_SYSC_OMAP36XX_SR,
659 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
660 .regbits = &sysc_regbits_omap36xx_sr,
661 .mod_quirks = SYSC_QUIRK_UNCACHED,
662};
663
664static const struct sysc_capabilities sysc_omap4_sr = {
665 .type = TI_SYSC_OMAP4_SR,
666 .regbits = &sysc_regbits_omap36xx_sr,
667};
668
669/*
670 * McASP register bits found on omap4 and later
671 */
672static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
673 .dmadisable_shift = -ENODEV,
674 .midle_shift = -ENODEV,
675 .sidle_shift = 0,
676 .clkact_shift = -ENODEV,
677 .enwkup_shift = -ENODEV,
678 .srst_shift = -ENODEV,
679 .emufree_shift = -ENODEV,
680 .autoidle_shift = -ENODEV,
681};
682
683static const struct sysc_capabilities sysc_omap4_mcasp = {
684 .type = TI_SYSC_OMAP4_MCASP,
685 .regbits = &sysc_regbits_omap4_mcasp,
686};
687
688/*
689 * FS USB host found on omap4 and later
690 */
691static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
692 .dmadisable_shift = -ENODEV,
693 .midle_shift = -ENODEV,
694 .sidle_shift = 24,
695 .clkact_shift = -ENODEV,
696 .enwkup_shift = 26,
697 .srst_shift = -ENODEV,
698 .emufree_shift = -ENODEV,
699 .autoidle_shift = -ENODEV,
700};
701
702static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
703 .type = TI_SYSC_OMAP4_USB_HOST_FS,
704 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
705 .regbits = &sysc_regbits_omap4_usb_host_fs,
706};
707
708static int sysc_init_match(struct sysc *ddata)
709{
710 const struct sysc_capabilities *cap;
711
712 cap = of_device_get_match_data(ddata->dev);
713 if (!cap)
714 return -EINVAL;
715
716 ddata->cap = cap;
717 if (ddata->cap)
718 ddata->cfg.quirks |= ddata->cap->mod_quirks;
719
720 return 0;
721}
722
Tony Lindgren0eecc632017-10-10 14:23:43 -0700723static int sysc_probe(struct platform_device *pdev)
724{
725 struct device_node *np = pdev->dev.of_node;
726 struct sysc *ddata;
727 int error;
728
729 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
730 if (!ddata)
731 return -ENOMEM;
732
733 ddata->dev = &pdev->dev;
734 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
735
Tony Lindgren70a65242017-12-15 09:41:09 -0800736 error = sysc_init_match(ddata);
737 if (error)
738 return error;
739
Tony Lindgren0eecc632017-10-10 14:23:43 -0700740 error = sysc_get_clocks(ddata);
741 if (error)
742 return error;
743
744 error = sysc_map_and_check_registers(ddata);
745 if (error)
746 goto unprepare;
747
748 platform_set_drvdata(pdev, ddata);
749
750 pm_runtime_enable(ddata->dev);
751 error = pm_runtime_get_sync(ddata->dev);
752 if (error < 0) {
753 pm_runtime_put_noidle(ddata->dev);
754 pm_runtime_disable(ddata->dev);
755 goto unprepare;
756 }
757
758 pm_runtime_use_autosuspend(ddata->dev);
759
760 sysc_show_registers(ddata);
761
762 error = of_platform_populate(ddata->dev->of_node,
763 NULL, NULL, ddata->dev);
764 if (error)
765 goto err;
766
767 pm_runtime_mark_last_busy(ddata->dev);
768 pm_runtime_put_autosuspend(ddata->dev);
769
770 return 0;
771
772err:
773 pm_runtime_dont_use_autosuspend(&pdev->dev);
774 pm_runtime_put_sync(&pdev->dev);
775 pm_runtime_disable(&pdev->dev);
776unprepare:
777 sysc_unprepare(ddata);
778
779 return error;
780}
781
Tony Lindgren684be5a2017-10-13 10:48:40 -0700782static int sysc_remove(struct platform_device *pdev)
783{
784 struct sysc *ddata = platform_get_drvdata(pdev);
785 int error;
786
787 error = pm_runtime_get_sync(ddata->dev);
788 if (error < 0) {
789 pm_runtime_put_noidle(ddata->dev);
790 pm_runtime_disable(ddata->dev);
791 goto unprepare;
792 }
793
794 of_platform_depopulate(&pdev->dev);
795
796 pm_runtime_dont_use_autosuspend(&pdev->dev);
797 pm_runtime_put_sync(&pdev->dev);
798 pm_runtime_disable(&pdev->dev);
799
800unprepare:
801 sysc_unprepare(ddata);
802
803 return 0;
804}
805
Tony Lindgren0eecc632017-10-10 14:23:43 -0700806static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -0800807 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
808 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
809 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
810 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
811 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
812 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
813 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
814 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
815 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
816 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
817 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
818 { .compatible = "ti,sysc-usb-host-fs",
819 .data = &sysc_omap4_usb_host_fs, },
Tony Lindgren0eecc632017-10-10 14:23:43 -0700820 { },
821};
822MODULE_DEVICE_TABLE(of, sysc_match);
823
824static struct platform_driver sysc_driver = {
825 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -0700826 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -0700827 .driver = {
828 .name = "ti-sysc",
829 .of_match_table = sysc_match,
830 .pm = &sysc_pm_ops,
831 },
832};
833module_platform_driver(sysc_driver);
834
835MODULE_DESCRIPTION("TI sysc interconnect target driver");
836MODULE_LICENSE("GPL v2");