blob: 3ffe5446ff3455e048bcd6016b8d4f3db45ccf7b [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 Lindgren0eecc632017-10-10 14:23:43 -070017#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/pm_runtime.h>
20#include <linux/of_address.h>
21#include <linux/of_platform.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080022#include <linux/slab.h>
23
Tony Lindgren70a65242017-12-15 09:41:09 -080024#include <linux/platform_data/ti-sysc.h>
25
26#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070027
28enum sysc_registers {
29 SYSC_REVISION,
30 SYSC_SYSCONFIG,
31 SYSC_SYSSTATUS,
32 SYSC_MAX_REGS,
33};
34
35static const char * const reg_names[] = { "rev", "sysc", "syss", };
36
37enum sysc_clocks {
38 SYSC_FCK,
39 SYSC_ICK,
40 SYSC_MAX_CLOCKS,
41};
42
43static const char * const clock_names[] = { "fck", "ick", };
44
Tony Lindgrenc5a2de92017-12-15 09:41:23 -080045#define SYSC_IDLEMODE_MASK 3
46#define SYSC_CLOCKACTIVITY_MASK 3
47
Tony Lindgren0eecc632017-10-10 14:23:43 -070048/**
49 * struct sysc - TI sysc interconnect target module registers and capabilities
50 * @dev: struct device pointer
51 * @module_pa: physical address of the interconnect target module
52 * @module_size: size of the interconnect target module
53 * @module_va: virtual address of the interconnect target module
54 * @offsets: register offsets from module base
55 * @clocks: clocks used by the interconnect target module
56 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -080057 * @cap: interconnect target module capabilities
58 * @cfg: interconnect target module configuration
Tony Lindgren566a9b052017-12-15 09:41:19 -080059 * @name: name if available
60 * @revision: interconnect target module revision
Tony Lindgren0eecc632017-10-10 14:23:43 -070061 */
62struct sysc {
63 struct device *dev;
64 u64 module_pa;
65 u32 module_size;
66 void __iomem *module_va;
67 int offsets[SYSC_MAX_REGS];
68 struct clk *clocks[SYSC_MAX_CLOCKS];
69 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -080070 const struct sysc_capabilities *cap;
71 struct sysc_config cfg;
Tony Lindgren566a9b052017-12-15 09:41:19 -080072 const char *name;
73 u32 revision;
Tony Lindgren0eecc632017-10-10 14:23:43 -070074};
75
Tony Lindgren566a9b052017-12-15 09:41:19 -080076static u32 sysc_read(struct sysc *ddata, int offset)
77{
78 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
79 u32 val;
80
81 val = readw_relaxed(ddata->module_va + offset);
82 val |= (readw_relaxed(ddata->module_va + offset + 4) << 16);
83
84 return val;
85 }
86
87 return readl_relaxed(ddata->module_va + offset);
88}
89
Tony Lindgren0eecc632017-10-10 14:23:43 -070090static u32 sysc_read_revision(struct sysc *ddata)
91{
Tony Lindgren566a9b052017-12-15 09:41:19 -080092 int offset = ddata->offsets[SYSC_REVISION];
93
94 if (offset < 0)
95 return 0;
96
97 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -070098}
99
100static int sysc_get_one_clock(struct sysc *ddata,
101 enum sysc_clocks index)
102{
103 const char *name;
104 int error;
105
106 switch (index) {
107 case SYSC_FCK:
108 break;
109 case SYSC_ICK:
110 break;
111 default:
112 return -EINVAL;
113 }
114 name = clock_names[index];
115
116 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
117 if (IS_ERR(ddata->clocks[index])) {
118 if (PTR_ERR(ddata->clocks[index]) == -ENOENT)
119 return 0;
120
121 dev_err(ddata->dev, "clock get error for %s: %li\n",
122 name, PTR_ERR(ddata->clocks[index]));
123
124 return PTR_ERR(ddata->clocks[index]);
125 }
126
127 error = clk_prepare(ddata->clocks[index]);
128 if (error) {
129 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
130 name, error);
131
132 return error;
133 }
134
135 return 0;
136}
137
138static int sysc_get_clocks(struct sysc *ddata)
139{
140 int i, error;
141
Tony Lindgren0eecc632017-10-10 14:23:43 -0700142 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
143 error = sysc_get_one_clock(ddata, i);
144 if (error && error != -ENOENT)
145 return error;
146 }
147
148 return 0;
149}
150
151/**
152 * sysc_parse_and_check_child_range - parses module IO region from ranges
153 * @ddata: device driver data
154 *
155 * In general we only need rev, syss, and sysc registers and not the whole
156 * module range. But we do want the offsets for these registers from the
157 * module base. This allows us to check them against the legacy hwmod
158 * platform data. Let's also check the ranges are configured properly.
159 */
160static int sysc_parse_and_check_child_range(struct sysc *ddata)
161{
162 struct device_node *np = ddata->dev->of_node;
163 const __be32 *ranges;
164 u32 nr_addr, nr_size;
165 int len, error;
166
167 ranges = of_get_property(np, "ranges", &len);
168 if (!ranges) {
169 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
170
171 return -ENOENT;
172 }
173
174 len /= sizeof(*ranges);
175
176 if (len < 3) {
177 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
178
179 return -EINVAL;
180 }
181
182 error = of_property_read_u32(np, "#address-cells", &nr_addr);
183 if (error)
184 return -ENOENT;
185
186 error = of_property_read_u32(np, "#size-cells", &nr_size);
187 if (error)
188 return -ENOENT;
189
190 if (nr_addr != 1 || nr_size != 1) {
191 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
192
193 return -EINVAL;
194 }
195
196 ranges++;
197 ddata->module_pa = of_translate_address(np, ranges++);
198 ddata->module_size = be32_to_cpup(ranges);
199
200 dev_dbg(ddata->dev, "interconnect target 0x%llx size 0x%x for %pOF\n",
201 ddata->module_pa, ddata->module_size, np);
202
203 return 0;
204}
205
206/**
207 * sysc_check_one_child - check child configuration
208 * @ddata: device driver data
209 * @np: child device node
210 *
211 * Let's avoid messy situations where we have new interconnect target
212 * node but children have "ti,hwmods". These belong to the interconnect
213 * target node and are managed by this driver.
214 */
215static int sysc_check_one_child(struct sysc *ddata,
216 struct device_node *np)
217{
218 const char *name;
219
220 name = of_get_property(np, "ti,hwmods", NULL);
221 if (name)
222 dev_warn(ddata->dev, "really a child ti,hwmods property?");
223
224 return 0;
225}
226
227static int sysc_check_children(struct sysc *ddata)
228{
229 struct device_node *child;
230 int error;
231
232 for_each_child_of_node(ddata->dev->of_node, child) {
233 error = sysc_check_one_child(ddata, child);
234 if (error)
235 return error;
236 }
237
238 return 0;
239}
240
Tony Lindgrena7199e22017-12-15 09:41:14 -0800241/*
242 * So far only I2C uses 16-bit read access with clockactivity with revision
243 * in two registers with stride of 4. We can detect this based on the rev
244 * register size to configure things far enough to be able to properly read
245 * the revision register.
246 */
247static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
248{
249 if (resource_size(res) == 8) {
250 dev_dbg(ddata->dev,
251 "enabling 16-bit and clockactivity quirks\n");
252 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
253 }
254}
255
Tony Lindgren0eecc632017-10-10 14:23:43 -0700256/**
257 * sysc_parse_one - parses the interconnect target module registers
258 * @ddata: device driver data
259 * @reg: register to parse
260 */
261static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
262{
263 struct resource *res;
264 const char *name;
265
266 switch (reg) {
267 case SYSC_REVISION:
268 case SYSC_SYSCONFIG:
269 case SYSC_SYSSTATUS:
270 name = reg_names[reg];
271 break;
272 default:
273 return -EINVAL;
274 }
275
276 res = platform_get_resource_byname(to_platform_device(ddata->dev),
277 IORESOURCE_MEM, name);
278 if (!res) {
279 dev_dbg(ddata->dev, "has no %s register\n", name);
280 ddata->offsets[reg] = -ENODEV;
281
282 return 0;
283 }
284
285 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800286 if (reg == SYSC_REVISION)
287 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700288
289 return 0;
290}
291
292static int sysc_parse_registers(struct sysc *ddata)
293{
294 int i, error;
295
296 for (i = 0; i < SYSC_MAX_REGS; i++) {
297 error = sysc_parse_one(ddata, i);
298 if (error)
299 return error;
300 }
301
302 return 0;
303}
304
305/**
306 * sysc_check_registers - check for misconfigured register overlaps
307 * @ddata: device driver data
308 */
309static int sysc_check_registers(struct sysc *ddata)
310{
311 int i, j, nr_regs = 0, nr_matches = 0;
312
313 for (i = 0; i < SYSC_MAX_REGS; i++) {
314 if (ddata->offsets[i] < 0)
315 continue;
316
317 if (ddata->offsets[i] > (ddata->module_size - 4)) {
318 dev_err(ddata->dev, "register outside module range");
319
320 return -EINVAL;
321 }
322
323 for (j = 0; j < SYSC_MAX_REGS; j++) {
324 if (ddata->offsets[j] < 0)
325 continue;
326
327 if (ddata->offsets[i] == ddata->offsets[j])
328 nr_matches++;
329 }
330 nr_regs++;
331 }
332
333 if (nr_regs < 1) {
334 dev_err(ddata->dev, "missing registers\n");
335
336 return -EINVAL;
337 }
338
339 if (nr_matches > nr_regs) {
340 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
341 nr_regs, nr_matches);
342
343 return -EINVAL;
344 }
345
346 return 0;
347}
348
349/**
350 * syc_ioremap - ioremap register space for the interconnect target module
351 * @ddata: deviec driver data
352 *
353 * Note that the interconnect target module registers can be anywhere
354 * within the first child device address space. For example, SGX has
355 * them at offset 0x1fc00 in the 32MB module address space. We just
356 * what we need around the interconnect target module registers.
357 */
358static int sysc_ioremap(struct sysc *ddata)
359{
360 u32 size = 0;
361
362 if (ddata->offsets[SYSC_SYSSTATUS] >= 0)
363 size = ddata->offsets[SYSC_SYSSTATUS];
364 else if (ddata->offsets[SYSC_SYSCONFIG] >= 0)
365 size = ddata->offsets[SYSC_SYSCONFIG];
366 else if (ddata->offsets[SYSC_REVISION] >= 0)
367 size = ddata->offsets[SYSC_REVISION];
368 else
369 return -EINVAL;
370
371 size &= 0xfff00;
372 size += SZ_256;
373
374 ddata->module_va = devm_ioremap(ddata->dev,
375 ddata->module_pa,
376 size);
377 if (!ddata->module_va)
378 return -EIO;
379
380 return 0;
381}
382
383/**
384 * sysc_map_and_check_registers - ioremap and check device registers
385 * @ddata: device driver data
386 */
387static int sysc_map_and_check_registers(struct sysc *ddata)
388{
389 int error;
390
391 error = sysc_parse_and_check_child_range(ddata);
392 if (error)
393 return error;
394
395 error = sysc_check_children(ddata);
396 if (error)
397 return error;
398
399 error = sysc_parse_registers(ddata);
400 if (error)
401 return error;
402
403 error = sysc_ioremap(ddata);
404 if (error)
405 return error;
406
407 error = sysc_check_registers(ddata);
408 if (error)
409 return error;
410
411 return 0;
412}
413
414/**
415 * sysc_show_rev - read and show interconnect target module revision
416 * @bufp: buffer to print the information to
417 * @ddata: device driver data
418 */
419static int sysc_show_rev(char *bufp, struct sysc *ddata)
420{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800421 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700422
423 if (ddata->offsets[SYSC_REVISION] < 0)
424 return sprintf(bufp, ":NA");
425
Tony Lindgren566a9b052017-12-15 09:41:19 -0800426 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700427
428 return len;
429}
430
431static int sysc_show_reg(struct sysc *ddata,
432 char *bufp, enum sysc_registers reg)
433{
434 if (ddata->offsets[reg] < 0)
435 return sprintf(bufp, ":NA");
436
437 return sprintf(bufp, ":%x", ddata->offsets[reg]);
438}
439
440/**
441 * sysc_show_registers - show information about interconnect target module
442 * @ddata: device driver data
443 */
444static void sysc_show_registers(struct sysc *ddata)
445{
446 char buf[128];
447 char *bufp = buf;
448 int i;
449
450 for (i = 0; i < SYSC_MAX_REGS; i++)
451 bufp += sysc_show_reg(ddata, bufp, i);
452
453 bufp += sysc_show_rev(bufp, ddata);
454
455 dev_dbg(ddata->dev, "%llx:%x%s\n",
456 ddata->module_pa, ddata->module_size,
457 buf);
458}
459
Arnd Bergmanna4a5d492017-10-13 11:25:32 +0200460static int __maybe_unused sysc_runtime_suspend(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700461{
462 struct sysc *ddata;
463 int i;
464
465 ddata = dev_get_drvdata(dev);
466
467 if (ddata->legacy_mode)
468 return 0;
469
470 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
471 if (IS_ERR_OR_NULL(ddata->clocks[i]))
472 continue;
473 clk_disable(ddata->clocks[i]);
474 }
475
476 return 0;
477}
478
Arnd Bergmanna4a5d492017-10-13 11:25:32 +0200479static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700480{
481 struct sysc *ddata;
482 int i, error;
483
484 ddata = dev_get_drvdata(dev);
485
486 if (ddata->legacy_mode)
487 return 0;
488
489 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
490 if (IS_ERR_OR_NULL(ddata->clocks[i]))
491 continue;
492 error = clk_enable(ddata->clocks[i]);
493 if (error)
494 return error;
495 }
496
497 return 0;
498}
499
500static const struct dev_pm_ops sysc_pm_ops = {
501 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
502 sysc_runtime_resume,
503 NULL)
504};
505
Tony Lindgren566a9b052017-12-15 09:41:19 -0800506/* At this point the module is configured enough to read the revision */
507static int sysc_init_module(struct sysc *ddata)
508{
509 int error;
510
511 error = pm_runtime_get_sync(ddata->dev);
512 if (error < 0) {
513 pm_runtime_put_noidle(ddata->dev);
514
515 return 0;
516 }
517 ddata->revision = sysc_read_revision(ddata);
518 pm_runtime_put_sync(ddata->dev);
519
520 return 0;
521}
522
Tony Lindgrenc5a2de92017-12-15 09:41:23 -0800523static int sysc_init_sysc_mask(struct sysc *ddata)
524{
525 struct device_node *np = ddata->dev->of_node;
526 int error;
527 u32 val;
528
529 error = of_property_read_u32(np, "ti,sysc-mask", &val);
530 if (error)
531 return 0;
532
533 if (val)
534 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
535 else
536 ddata->cfg.sysc_val = ddata->cap->sysc_mask;
537
538 return 0;
539}
540
541static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
542 const char *name)
543{
544 struct device_node *np = ddata->dev->of_node;
545 struct property *prop;
546 const __be32 *p;
547 u32 val;
548
549 of_property_for_each_u32(np, name, prop, p, val) {
550 if (val >= SYSC_NR_IDLEMODES) {
551 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
552 return -EINVAL;
553 }
554 *idlemodes |= (1 << val);
555 }
556
557 return 0;
558}
559
560static int sysc_init_idlemodes(struct sysc *ddata)
561{
562 int error;
563
564 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
565 "ti,sysc-midle");
566 if (error)
567 return error;
568
569 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
570 "ti,sysc-sidle");
571 if (error)
572 return error;
573
574 return 0;
575}
576
577/*
578 * Only some devices on omap4 and later have SYSCONFIG reset done
579 * bit. We can detect this if there is no SYSSTATUS at all, or the
580 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
581 * have multiple bits for the child devices like OHCI and EHCI.
582 * Depends on SYSC being parsed first.
583 */
584static int sysc_init_syss_mask(struct sysc *ddata)
585{
586 struct device_node *np = ddata->dev->of_node;
587 int error;
588 u32 val;
589
590 error = of_property_read_u32(np, "ti,syss-mask", &val);
591 if (error) {
592 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
593 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
594 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
595 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
596
597 return 0;
598 }
599
600 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
601 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
602
603 ddata->cfg.syss_mask = val;
604
605 return 0;
606}
607
Tony Lindgren2c355ff2018-02-22 13:58:03 -0800608/*
609 * Many child device drivers need to have fck available to get the clock
610 * rate for device internal configuration.
611 */
612static int sysc_child_add_fck(struct sysc *ddata,
613 struct device *child)
614{
615 struct clk *fck;
616 struct clk_lookup *l;
617 const char *name = clock_names[SYSC_FCK];
618
619 if (IS_ERR_OR_NULL(ddata->clocks[SYSC_FCK]))
620 return 0;
621
622 fck = clk_get(child, name);
623 if (!IS_ERR(fck)) {
624 clk_put(fck);
625
626 return -EEXIST;
627 }
628
629 l = clkdev_create(ddata->clocks[SYSC_FCK], name, dev_name(child));
630
631 return l ? 0 : -ENODEV;
632}
633
634static struct device_type sysc_device_type = {
635};
636
637static struct sysc *sysc_child_to_parent(struct device *dev)
638{
639 struct device *parent = dev->parent;
640
641 if (!parent || parent->type != &sysc_device_type)
642 return NULL;
643
644 return dev_get_drvdata(parent);
645}
646
647static int sysc_notifier_call(struct notifier_block *nb,
648 unsigned long event, void *device)
649{
650 struct device *dev = device;
651 struct sysc *ddata;
652 int error;
653
654 ddata = sysc_child_to_parent(dev);
655 if (!ddata)
656 return NOTIFY_DONE;
657
658 switch (event) {
659 case BUS_NOTIFY_ADD_DEVICE:
660 error = sysc_child_add_fck(ddata, dev);
661 if (error && error != -EEXIST)
662 dev_warn(ddata->dev, "could not add %s fck: %i\n",
663 dev_name(dev), error);
664 break;
665 default:
666 break;
667 }
668
669 return NOTIFY_DONE;
670}
671
672static struct notifier_block sysc_nb = {
673 .notifier_call = sysc_notifier_call,
674};
675
Tony Lindgren566a9b052017-12-15 09:41:19 -0800676/* Device tree configured quirks */
677struct sysc_dts_quirk {
678 const char *name;
679 u32 mask;
680};
681
682static const struct sysc_dts_quirk sysc_dts_quirks[] = {
683 { .name = "ti,no-idle-on-init",
684 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
685 { .name = "ti,no-reset-on-init",
686 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
687};
688
689static int sysc_init_dts_quirks(struct sysc *ddata)
690{
691 struct device_node *np = ddata->dev->of_node;
692 const struct property *prop;
693 int i, len, error;
694 u32 val;
695
696 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
697
698 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
699 prop = of_get_property(np, sysc_dts_quirks[i].name, &len);
700 if (!prop)
701 break;
702
703 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
704 }
705
706 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
707 if (!error) {
708 if (val > 255) {
709 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
710 val);
711 }
712
713 ddata->cfg.srst_udelay = (u8)val;
714 }
715
716 return 0;
717}
718
Tony Lindgren0eecc632017-10-10 14:23:43 -0700719static void sysc_unprepare(struct sysc *ddata)
720{
721 int i;
722
723 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
724 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
725 clk_unprepare(ddata->clocks[i]);
726 }
727}
728
Tony Lindgren70a65242017-12-15 09:41:09 -0800729/*
730 * Common sysc register bits found on omap2, also known as type1
731 */
732static const struct sysc_regbits sysc_regbits_omap2 = {
733 .dmadisable_shift = -ENODEV,
734 .midle_shift = 12,
735 .sidle_shift = 3,
736 .clkact_shift = 8,
737 .emufree_shift = 5,
738 .enwkup_shift = 2,
739 .srst_shift = 1,
740 .autoidle_shift = 0,
741};
742
743static const struct sysc_capabilities sysc_omap2 = {
744 .type = TI_SYSC_OMAP2,
745 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
746 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
747 SYSC_OMAP2_AUTOIDLE,
748 .regbits = &sysc_regbits_omap2,
749};
750
751/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
752static const struct sysc_capabilities sysc_omap2_timer = {
753 .type = TI_SYSC_OMAP2_TIMER,
754 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
755 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
756 SYSC_OMAP2_AUTOIDLE,
757 .regbits = &sysc_regbits_omap2,
758 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
759};
760
761/*
762 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
763 * with different sidle position
764 */
765static const struct sysc_regbits sysc_regbits_omap3_sham = {
766 .dmadisable_shift = -ENODEV,
767 .midle_shift = -ENODEV,
768 .sidle_shift = 4,
769 .clkact_shift = -ENODEV,
770 .enwkup_shift = -ENODEV,
771 .srst_shift = 1,
772 .autoidle_shift = 0,
773 .emufree_shift = -ENODEV,
774};
775
776static const struct sysc_capabilities sysc_omap3_sham = {
777 .type = TI_SYSC_OMAP3_SHAM,
778 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
779 .regbits = &sysc_regbits_omap3_sham,
780};
781
782/*
783 * AES register bits found on omap3 and later, a variant of
784 * sysc_regbits_omap2 with different sidle position
785 */
786static const struct sysc_regbits sysc_regbits_omap3_aes = {
787 .dmadisable_shift = -ENODEV,
788 .midle_shift = -ENODEV,
789 .sidle_shift = 6,
790 .clkact_shift = -ENODEV,
791 .enwkup_shift = -ENODEV,
792 .srst_shift = 1,
793 .autoidle_shift = 0,
794 .emufree_shift = -ENODEV,
795};
796
797static const struct sysc_capabilities sysc_omap3_aes = {
798 .type = TI_SYSC_OMAP3_AES,
799 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
800 .regbits = &sysc_regbits_omap3_aes,
801};
802
803/*
804 * Common sysc register bits found on omap4, also known as type2
805 */
806static const struct sysc_regbits sysc_regbits_omap4 = {
807 .dmadisable_shift = 16,
808 .midle_shift = 4,
809 .sidle_shift = 2,
810 .clkact_shift = -ENODEV,
811 .enwkup_shift = -ENODEV,
812 .emufree_shift = 1,
813 .srst_shift = 0,
814 .autoidle_shift = -ENODEV,
815};
816
817static const struct sysc_capabilities sysc_omap4 = {
818 .type = TI_SYSC_OMAP4,
819 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
820 SYSC_OMAP4_SOFTRESET,
821 .regbits = &sysc_regbits_omap4,
822};
823
824static const struct sysc_capabilities sysc_omap4_timer = {
825 .type = TI_SYSC_OMAP4_TIMER,
826 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
827 SYSC_OMAP4_SOFTRESET,
828 .regbits = &sysc_regbits_omap4,
829};
830
831/*
832 * Common sysc register bits found on omap4, also known as type3
833 */
834static const struct sysc_regbits sysc_regbits_omap4_simple = {
835 .dmadisable_shift = -ENODEV,
836 .midle_shift = 2,
837 .sidle_shift = 0,
838 .clkact_shift = -ENODEV,
839 .enwkup_shift = -ENODEV,
840 .srst_shift = -ENODEV,
841 .emufree_shift = -ENODEV,
842 .autoidle_shift = -ENODEV,
843};
844
845static const struct sysc_capabilities sysc_omap4_simple = {
846 .type = TI_SYSC_OMAP4_SIMPLE,
847 .regbits = &sysc_regbits_omap4_simple,
848};
849
850/*
851 * SmartReflex sysc found on omap34xx
852 */
853static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
854 .dmadisable_shift = -ENODEV,
855 .midle_shift = -ENODEV,
856 .sidle_shift = -ENODEV,
857 .clkact_shift = 20,
858 .enwkup_shift = -ENODEV,
859 .srst_shift = -ENODEV,
860 .emufree_shift = -ENODEV,
861 .autoidle_shift = -ENODEV,
862};
863
864static const struct sysc_capabilities sysc_34xx_sr = {
865 .type = TI_SYSC_OMAP34XX_SR,
866 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
867 .regbits = &sysc_regbits_omap34xx_sr,
868 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED,
869};
870
871/*
872 * SmartReflex sysc found on omap36xx and later
873 */
874static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
875 .dmadisable_shift = -ENODEV,
876 .midle_shift = -ENODEV,
877 .sidle_shift = 24,
878 .clkact_shift = -ENODEV,
879 .enwkup_shift = 26,
880 .srst_shift = -ENODEV,
881 .emufree_shift = -ENODEV,
882 .autoidle_shift = -ENODEV,
883};
884
885static const struct sysc_capabilities sysc_36xx_sr = {
886 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -0800887 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -0800888 .regbits = &sysc_regbits_omap36xx_sr,
889 .mod_quirks = SYSC_QUIRK_UNCACHED,
890};
891
892static const struct sysc_capabilities sysc_omap4_sr = {
893 .type = TI_SYSC_OMAP4_SR,
894 .regbits = &sysc_regbits_omap36xx_sr,
895};
896
897/*
898 * McASP register bits found on omap4 and later
899 */
900static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
901 .dmadisable_shift = -ENODEV,
902 .midle_shift = -ENODEV,
903 .sidle_shift = 0,
904 .clkact_shift = -ENODEV,
905 .enwkup_shift = -ENODEV,
906 .srst_shift = -ENODEV,
907 .emufree_shift = -ENODEV,
908 .autoidle_shift = -ENODEV,
909};
910
911static const struct sysc_capabilities sysc_omap4_mcasp = {
912 .type = TI_SYSC_OMAP4_MCASP,
913 .regbits = &sysc_regbits_omap4_mcasp,
914};
915
916/*
917 * FS USB host found on omap4 and later
918 */
919static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
920 .dmadisable_shift = -ENODEV,
921 .midle_shift = -ENODEV,
922 .sidle_shift = 24,
923 .clkact_shift = -ENODEV,
924 .enwkup_shift = 26,
925 .srst_shift = -ENODEV,
926 .emufree_shift = -ENODEV,
927 .autoidle_shift = -ENODEV,
928};
929
930static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
931 .type = TI_SYSC_OMAP4_USB_HOST_FS,
932 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
933 .regbits = &sysc_regbits_omap4_usb_host_fs,
934};
935
936static int sysc_init_match(struct sysc *ddata)
937{
938 const struct sysc_capabilities *cap;
939
940 cap = of_device_get_match_data(ddata->dev);
941 if (!cap)
942 return -EINVAL;
943
944 ddata->cap = cap;
945 if (ddata->cap)
946 ddata->cfg.quirks |= ddata->cap->mod_quirks;
947
948 return 0;
949}
950
Tony Lindgren0eecc632017-10-10 14:23:43 -0700951static int sysc_probe(struct platform_device *pdev)
952{
Tony Lindgren0eecc632017-10-10 14:23:43 -0700953 struct sysc *ddata;
954 int error;
955
956 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
957 if (!ddata)
958 return -ENOMEM;
959
960 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -0800961 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700962
Tony Lindgren70a65242017-12-15 09:41:09 -0800963 error = sysc_init_match(ddata);
964 if (error)
965 return error;
966
Tony Lindgren566a9b052017-12-15 09:41:19 -0800967 error = sysc_init_dts_quirks(ddata);
968 if (error)
969 goto unprepare;
970
Tony Lindgren0eecc632017-10-10 14:23:43 -0700971 error = sysc_get_clocks(ddata);
972 if (error)
973 return error;
974
975 error = sysc_map_and_check_registers(ddata);
976 if (error)
977 goto unprepare;
978
Tony Lindgrenc5a2de92017-12-15 09:41:23 -0800979 error = sysc_init_sysc_mask(ddata);
980 if (error)
981 goto unprepare;
982
983 error = sysc_init_idlemodes(ddata);
984 if (error)
985 goto unprepare;
986
987 error = sysc_init_syss_mask(ddata);
988 if (error)
989 goto unprepare;
990
Tony Lindgren0eecc632017-10-10 14:23:43 -0700991 pm_runtime_enable(ddata->dev);
Tony Lindgren566a9b052017-12-15 09:41:19 -0800992
993 error = sysc_init_module(ddata);
994 if (error)
995 goto unprepare;
996
Tony Lindgren0eecc632017-10-10 14:23:43 -0700997 error = pm_runtime_get_sync(ddata->dev);
998 if (error < 0) {
999 pm_runtime_put_noidle(ddata->dev);
1000 pm_runtime_disable(ddata->dev);
1001 goto unprepare;
1002 }
1003
1004 pm_runtime_use_autosuspend(ddata->dev);
1005
1006 sysc_show_registers(ddata);
1007
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001008 ddata->dev->type = &sysc_device_type;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001009 error = of_platform_populate(ddata->dev->of_node,
1010 NULL, NULL, ddata->dev);
1011 if (error)
1012 goto err;
1013
1014 pm_runtime_mark_last_busy(ddata->dev);
1015 pm_runtime_put_autosuspend(ddata->dev);
1016
1017 return 0;
1018
1019err:
1020 pm_runtime_dont_use_autosuspend(&pdev->dev);
1021 pm_runtime_put_sync(&pdev->dev);
1022 pm_runtime_disable(&pdev->dev);
1023unprepare:
1024 sysc_unprepare(ddata);
1025
1026 return error;
1027}
1028
Tony Lindgren684be5a2017-10-13 10:48:40 -07001029static int sysc_remove(struct platform_device *pdev)
1030{
1031 struct sysc *ddata = platform_get_drvdata(pdev);
1032 int error;
1033
1034 error = pm_runtime_get_sync(ddata->dev);
1035 if (error < 0) {
1036 pm_runtime_put_noidle(ddata->dev);
1037 pm_runtime_disable(ddata->dev);
1038 goto unprepare;
1039 }
1040
1041 of_platform_depopulate(&pdev->dev);
1042
1043 pm_runtime_dont_use_autosuspend(&pdev->dev);
1044 pm_runtime_put_sync(&pdev->dev);
1045 pm_runtime_disable(&pdev->dev);
1046
1047unprepare:
1048 sysc_unprepare(ddata);
1049
1050 return 0;
1051}
1052
Tony Lindgren0eecc632017-10-10 14:23:43 -07001053static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08001054 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
1055 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
1056 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
1057 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
1058 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
1059 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
1060 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
1061 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
1062 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
1063 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
1064 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
1065 { .compatible = "ti,sysc-usb-host-fs",
1066 .data = &sysc_omap4_usb_host_fs, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07001067 { },
1068};
1069MODULE_DEVICE_TABLE(of, sysc_match);
1070
1071static struct platform_driver sysc_driver = {
1072 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07001073 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07001074 .driver = {
1075 .name = "ti-sysc",
1076 .of_match_table = sysc_match,
1077 .pm = &sysc_pm_ops,
1078 },
1079};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001080
1081static int __init sysc_init(void)
1082{
1083 bus_register_notifier(&platform_bus_type, &sysc_nb);
1084
1085 return platform_driver_register(&sysc_driver);
1086}
1087module_init(sysc_init);
1088
1089static void __exit sysc_exit(void)
1090{
1091 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
1092 platform_driver_unregister(&sysc_driver);
1093}
1094module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001095
1096MODULE_DESCRIPTION("TI sysc interconnect target driver");
1097MODULE_LICENSE("GPL v2");