1 // SPDX-License-Identifier: GPL-2.0
3 * ti-sysc.c - Texas Instruments sysc interconnect target driver
8 #include <linux/clkdev.h>
9 #include <linux/delay.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/pm_domain.h>
13 #include <linux/pm_runtime.h>
14 #include <linux/reset.h>
15 #include <linux/of_address.h>
16 #include <linux/of_platform.h>
17 #include <linux/slab.h>
18 #include <linux/iopoll.h>
20 #include <linux/platform_data/ti-sysc.h>
22 #include <dt-bindings/bus/ti-sysc.h>
24 #define MAX_MODULE_SOFTRESET_WAIT 10000
26 static const char * const reg_names
[] = { "rev", "sysc", "syss", };
42 static const char * const clock_names
[SYSC_MAX_CLOCKS
] = {
43 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
44 "opt5", "opt6", "opt7",
47 #define SYSC_IDLEMODE_MASK 3
48 #define SYSC_CLOCKACTIVITY_MASK 3
51 * struct sysc - TI sysc interconnect target module registers and capabilities
52 * @dev: struct device pointer
53 * @module_pa: physical address of the interconnect target module
54 * @module_size: size of the interconnect target module
55 * @module_va: virtual address of the interconnect target module
56 * @offsets: register offsets from module base
57 * @mdata: ti-sysc to hwmod translation data for a module
58 * @clocks: clocks used by the interconnect target module
59 * @clock_roles: clock role names for the found clocks
60 * @nr_clocks: number of clocks used by the interconnect target module
61 * @rsts: resets used by the interconnect target module
62 * @legacy_mode: configured for legacy mode if set
63 * @cap: interconnect target module capabilities
64 * @cfg: interconnect target module configuration
65 * @cookie: data used by legacy platform callbacks
66 * @name: name if available
67 * @revision: interconnect target module revision
68 * @enabled: sysc runtime enabled status
69 * @needs_resume: runtime resume needed on resume from suspend
70 * @child_needs_resume: runtime resume needed for child on resume from suspend
71 * @disable_on_idle: status flag used for disabling modules with resets
72 * @idle_work: work structure used to perform delayed idle on a module
73 * @clk_enable_quirk: module specific clock enable quirk
74 * @clk_disable_quirk: module specific clock disable quirk
75 * @reset_done_quirk: module specific reset done quirk
76 * @module_enable_quirk: module specific enable quirk
77 * @module_disable_quirk: module specific disable quirk
83 void __iomem
*module_va
;
84 int offsets
[SYSC_MAX_REGS
];
85 struct ti_sysc_module_data
*mdata
;
87 const char **clock_roles
;
89 struct reset_control
*rsts
;
90 const char *legacy_mode
;
91 const struct sysc_capabilities
*cap
;
92 struct sysc_config cfg
;
93 struct ti_sysc_cookie cookie
;
96 unsigned int enabled
:1;
97 unsigned int needs_resume
:1;
98 unsigned int child_needs_resume
:1;
99 struct delayed_work idle_work
;
100 void (*clk_enable_quirk
)(struct sysc
*sysc
);
101 void (*clk_disable_quirk
)(struct sysc
*sysc
);
102 void (*reset_done_quirk
)(struct sysc
*sysc
);
103 void (*module_enable_quirk
)(struct sysc
*sysc
);
104 void (*module_disable_quirk
)(struct sysc
*sysc
);
107 static void sysc_parse_dts_quirks(struct sysc
*ddata
, struct device_node
*np
,
110 static void sysc_write(struct sysc
*ddata
, int offset
, u32 value
)
112 if (ddata
->cfg
.quirks
& SYSC_QUIRK_16BIT
) {
113 writew_relaxed(value
& 0xffff, ddata
->module_va
+ offset
);
115 /* Only i2c revision has LO and HI register with stride of 4 */
116 if (ddata
->offsets
[SYSC_REVISION
] >= 0 &&
117 offset
== ddata
->offsets
[SYSC_REVISION
]) {
118 u16 hi
= value
>> 16;
120 writew_relaxed(hi
, ddata
->module_va
+ offset
+ 4);
126 writel_relaxed(value
, ddata
->module_va
+ offset
);
129 static u32
sysc_read(struct sysc
*ddata
, int offset
)
131 if (ddata
->cfg
.quirks
& SYSC_QUIRK_16BIT
) {
134 val
= readw_relaxed(ddata
->module_va
+ offset
);
136 /* Only i2c revision has LO and HI register with stride of 4 */
137 if (ddata
->offsets
[SYSC_REVISION
] >= 0 &&
138 offset
== ddata
->offsets
[SYSC_REVISION
]) {
139 u16 tmp
= readw_relaxed(ddata
->module_va
+ offset
+ 4);
147 return readl_relaxed(ddata
->module_va
+ offset
);
150 static bool sysc_opt_clks_needed(struct sysc
*ddata
)
152 return !!(ddata
->cfg
.quirks
& SYSC_QUIRK_OPT_CLKS_NEEDED
);
155 static u32
sysc_read_revision(struct sysc
*ddata
)
157 int offset
= ddata
->offsets
[SYSC_REVISION
];
162 return sysc_read(ddata
, offset
);
165 static u32
sysc_read_sysconfig(struct sysc
*ddata
)
167 int offset
= ddata
->offsets
[SYSC_SYSCONFIG
];
172 return sysc_read(ddata
, offset
);
175 static u32
sysc_read_sysstatus(struct sysc
*ddata
)
177 int offset
= ddata
->offsets
[SYSC_SYSSTATUS
];
182 return sysc_read(ddata
, offset
);
185 static int sysc_add_named_clock_from_child(struct sysc
*ddata
,
187 const char *optfck_name
)
189 struct device_node
*np
= ddata
->dev
->of_node
;
190 struct device_node
*child
;
191 struct clk_lookup
*cl
;
200 /* Does the clock alias already exist? */
201 clock
= of_clk_get_by_name(np
, n
);
202 if (!IS_ERR(clock
)) {
208 child
= of_get_next_available_child(np
, NULL
);
212 clock
= devm_get_clk_from_child(ddata
->dev
, child
, name
);
214 return PTR_ERR(clock
);
217 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
218 * limit for clk_get(). If cl ever needs to be freed, it should be done
219 * with clkdev_drop().
221 cl
= kcalloc(1, sizeof(*cl
), GFP_KERNEL
);
226 cl
->dev_id
= dev_name(ddata
->dev
);
235 static int sysc_init_ext_opt_clock(struct sysc
*ddata
, const char *name
)
237 const char *optfck_name
;
240 if (ddata
->nr_clocks
< SYSC_OPTFCK0
)
241 index
= SYSC_OPTFCK0
;
243 index
= ddata
->nr_clocks
;
248 optfck_name
= clock_names
[index
];
250 error
= sysc_add_named_clock_from_child(ddata
, name
, optfck_name
);
254 ddata
->clock_roles
[index
] = optfck_name
;
260 static int sysc_get_one_clock(struct sysc
*ddata
, const char *name
)
262 int error
, i
, index
= -ENODEV
;
264 if (!strncmp(clock_names
[SYSC_FCK
], name
, 3))
266 else if (!strncmp(clock_names
[SYSC_ICK
], name
, 3))
270 for (i
= SYSC_OPTFCK0
; i
< SYSC_MAX_CLOCKS
; i
++) {
271 if (!ddata
->clocks
[i
]) {
279 dev_err(ddata
->dev
, "clock %s not added\n", name
);
283 ddata
->clocks
[index
] = devm_clk_get(ddata
->dev
, name
);
284 if (IS_ERR(ddata
->clocks
[index
])) {
285 dev_err(ddata
->dev
, "clock get error for %s: %li\n",
286 name
, PTR_ERR(ddata
->clocks
[index
]));
288 return PTR_ERR(ddata
->clocks
[index
]);
291 error
= clk_prepare(ddata
->clocks
[index
]);
293 dev_err(ddata
->dev
, "clock prepare error for %s: %i\n",
302 static int sysc_get_clocks(struct sysc
*ddata
)
304 struct device_node
*np
= ddata
->dev
->of_node
;
305 struct property
*prop
;
307 int nr_fck
= 0, nr_ick
= 0, i
, error
= 0;
309 ddata
->clock_roles
= devm_kcalloc(ddata
->dev
,
311 sizeof(*ddata
->clock_roles
),
313 if (!ddata
->clock_roles
)
316 of_property_for_each_string(np
, "clock-names", prop
, name
) {
317 if (!strncmp(clock_names
[SYSC_FCK
], name
, 3))
319 if (!strncmp(clock_names
[SYSC_ICK
], name
, 3))
321 ddata
->clock_roles
[ddata
->nr_clocks
] = name
;
325 if (ddata
->nr_clocks
< 1)
328 if ((ddata
->cfg
.quirks
& SYSC_QUIRK_EXT_OPT_CLOCK
)) {
329 error
= sysc_init_ext_opt_clock(ddata
, NULL
);
334 if (ddata
->nr_clocks
> SYSC_MAX_CLOCKS
) {
335 dev_err(ddata
->dev
, "too many clocks for %pOF\n", np
);
340 if (nr_fck
> 1 || nr_ick
> 1) {
341 dev_err(ddata
->dev
, "max one fck and ick for %pOF\n", np
);
346 /* Always add a slot for main clocks fck and ick even if unused */
352 ddata
->clocks
= devm_kcalloc(ddata
->dev
,
353 ddata
->nr_clocks
, sizeof(*ddata
->clocks
),
358 for (i
= 0; i
< SYSC_MAX_CLOCKS
; i
++) {
359 const char *name
= ddata
->clock_roles
[i
];
364 error
= sysc_get_one_clock(ddata
, name
);
372 static int sysc_enable_main_clocks(struct sysc
*ddata
)
380 for (i
= 0; i
< SYSC_OPTFCK0
; i
++) {
381 clock
= ddata
->clocks
[i
];
383 /* Main clocks may not have ick */
384 if (IS_ERR_OR_NULL(clock
))
387 error
= clk_enable(clock
);
395 for (i
--; i
>= 0; i
--) {
396 clock
= ddata
->clocks
[i
];
398 /* Main clocks may not have ick */
399 if (IS_ERR_OR_NULL(clock
))
408 static void sysc_disable_main_clocks(struct sysc
*ddata
)
416 for (i
= 0; i
< SYSC_OPTFCK0
; i
++) {
417 clock
= ddata
->clocks
[i
];
418 if (IS_ERR_OR_NULL(clock
))
425 static int sysc_enable_opt_clocks(struct sysc
*ddata
)
430 if (!ddata
->clocks
|| ddata
->nr_clocks
< SYSC_OPTFCK0
+ 1)
433 for (i
= SYSC_OPTFCK0
; i
< SYSC_MAX_CLOCKS
; i
++) {
434 clock
= ddata
->clocks
[i
];
436 /* Assume no holes for opt clocks */
437 if (IS_ERR_OR_NULL(clock
))
440 error
= clk_enable(clock
);
448 for (i
--; i
>= 0; i
--) {
449 clock
= ddata
->clocks
[i
];
450 if (IS_ERR_OR_NULL(clock
))
459 static void sysc_disable_opt_clocks(struct sysc
*ddata
)
464 if (!ddata
->clocks
|| ddata
->nr_clocks
< SYSC_OPTFCK0
+ 1)
467 for (i
= SYSC_OPTFCK0
; i
< SYSC_MAX_CLOCKS
; i
++) {
468 clock
= ddata
->clocks
[i
];
470 /* Assume no holes for opt clocks */
471 if (IS_ERR_OR_NULL(clock
))
478 static void sysc_clkdm_deny_idle(struct sysc
*ddata
)
480 struct ti_sysc_platform_data
*pdata
;
482 if (ddata
->legacy_mode
)
485 pdata
= dev_get_platdata(ddata
->dev
);
486 if (pdata
&& pdata
->clkdm_deny_idle
)
487 pdata
->clkdm_deny_idle(ddata
->dev
, &ddata
->cookie
);
490 static void sysc_clkdm_allow_idle(struct sysc
*ddata
)
492 struct ti_sysc_platform_data
*pdata
;
494 if (ddata
->legacy_mode
)
497 pdata
= dev_get_platdata(ddata
->dev
);
498 if (pdata
&& pdata
->clkdm_allow_idle
)
499 pdata
->clkdm_allow_idle(ddata
->dev
, &ddata
->cookie
);
503 * sysc_init_resets - init rstctrl reset line if configured
504 * @ddata: device driver data
506 * See sysc_rstctrl_reset_deassert().
508 static int sysc_init_resets(struct sysc
*ddata
)
511 devm_reset_control_get_optional_shared(ddata
->dev
, "rstctrl");
512 if (IS_ERR(ddata
->rsts
))
513 return PTR_ERR(ddata
->rsts
);
519 * sysc_parse_and_check_child_range - parses module IO region from ranges
520 * @ddata: device driver data
522 * In general we only need rev, syss, and sysc registers and not the whole
523 * module range. But we do want the offsets for these registers from the
524 * module base. This allows us to check them against the legacy hwmod
525 * platform data. Let's also check the ranges are configured properly.
527 static int sysc_parse_and_check_child_range(struct sysc
*ddata
)
529 struct device_node
*np
= ddata
->dev
->of_node
;
530 const __be32
*ranges
;
531 u32 nr_addr
, nr_size
;
534 ranges
= of_get_property(np
, "ranges", &len
);
536 dev_err(ddata
->dev
, "missing ranges for %pOF\n", np
);
541 len
/= sizeof(*ranges
);
544 dev_err(ddata
->dev
, "incomplete ranges for %pOF\n", np
);
549 error
= of_property_read_u32(np
, "#address-cells", &nr_addr
);
553 error
= of_property_read_u32(np
, "#size-cells", &nr_size
);
557 if (nr_addr
!= 1 || nr_size
!= 1) {
558 dev_err(ddata
->dev
, "invalid ranges for %pOF\n", np
);
564 ddata
->module_pa
= of_translate_address(np
, ranges
++);
565 ddata
->module_size
= be32_to_cpup(ranges
);
570 static struct device_node
*stdout_path
;
572 static void sysc_init_stdout_path(struct sysc
*ddata
)
574 struct device_node
*np
= NULL
;
577 if (IS_ERR(stdout_path
))
583 np
= of_find_node_by_path("/chosen");
587 uart
= of_get_property(np
, "stdout-path", NULL
);
591 np
= of_find_node_by_path(uart
);
600 stdout_path
= ERR_PTR(-ENODEV
);
603 static void sysc_check_quirk_stdout(struct sysc
*ddata
,
604 struct device_node
*np
)
606 sysc_init_stdout_path(ddata
);
607 if (np
!= stdout_path
)
610 ddata
->cfg
.quirks
|= SYSC_QUIRK_NO_IDLE_ON_INIT
|
611 SYSC_QUIRK_NO_RESET_ON_INIT
;
615 * sysc_check_one_child - check child configuration
616 * @ddata: device driver data
617 * @np: child device node
619 * Let's avoid messy situations where we have new interconnect target
620 * node but children have "ti,hwmods". These belong to the interconnect
621 * target node and are managed by this driver.
623 static void sysc_check_one_child(struct sysc
*ddata
,
624 struct device_node
*np
)
628 name
= of_get_property(np
, "ti,hwmods", NULL
);
630 dev_warn(ddata
->dev
, "really a child ti,hwmods property?");
632 sysc_check_quirk_stdout(ddata
, np
);
633 sysc_parse_dts_quirks(ddata
, np
, true);
636 static void sysc_check_children(struct sysc
*ddata
)
638 struct device_node
*child
;
640 for_each_child_of_node(ddata
->dev
->of_node
, child
)
641 sysc_check_one_child(ddata
, child
);
645 * So far only I2C uses 16-bit read access with clockactivity with revision
646 * in two registers with stride of 4. We can detect this based on the rev
647 * register size to configure things far enough to be able to properly read
648 * the revision register.
650 static void sysc_check_quirk_16bit(struct sysc
*ddata
, struct resource
*res
)
652 if (resource_size(res
) == 8)
653 ddata
->cfg
.quirks
|= SYSC_QUIRK_16BIT
| SYSC_QUIRK_USE_CLOCKACT
;
657 * sysc_parse_one - parses the interconnect target module registers
658 * @ddata: device driver data
659 * @reg: register to parse
661 static int sysc_parse_one(struct sysc
*ddata
, enum sysc_registers reg
)
663 struct resource
*res
;
670 name
= reg_names
[reg
];
676 res
= platform_get_resource_byname(to_platform_device(ddata
->dev
),
677 IORESOURCE_MEM
, name
);
679 ddata
->offsets
[reg
] = -ENODEV
;
684 ddata
->offsets
[reg
] = res
->start
- ddata
->module_pa
;
685 if (reg
== SYSC_REVISION
)
686 sysc_check_quirk_16bit(ddata
, res
);
691 static int sysc_parse_registers(struct sysc
*ddata
)
695 for (i
= 0; i
< SYSC_MAX_REGS
; i
++) {
696 error
= sysc_parse_one(ddata
, i
);
705 * sysc_check_registers - check for misconfigured register overlaps
706 * @ddata: device driver data
708 static int sysc_check_registers(struct sysc
*ddata
)
710 int i
, j
, nr_regs
= 0, nr_matches
= 0;
712 for (i
= 0; i
< SYSC_MAX_REGS
; i
++) {
713 if (ddata
->offsets
[i
] < 0)
716 if (ddata
->offsets
[i
] > (ddata
->module_size
- 4)) {
717 dev_err(ddata
->dev
, "register outside module range");
722 for (j
= 0; j
< SYSC_MAX_REGS
; j
++) {
723 if (ddata
->offsets
[j
] < 0)
726 if (ddata
->offsets
[i
] == ddata
->offsets
[j
])
732 if (nr_matches
> nr_regs
) {
733 dev_err(ddata
->dev
, "overlapping registers: (%i/%i)",
734 nr_regs
, nr_matches
);
743 * syc_ioremap - ioremap register space for the interconnect target module
744 * @ddata: device driver data
746 * Note that the interconnect target module registers can be anywhere
747 * within the interconnect target module range. For example, SGX has
748 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
749 * has them at offset 0x1200 in the CPSW_WR child. Usually the
750 * the interconnect target module registers are at the beginning of
751 * the module range though.
753 static int sysc_ioremap(struct sysc
*ddata
)
757 if (ddata
->offsets
[SYSC_REVISION
] < 0 &&
758 ddata
->offsets
[SYSC_SYSCONFIG
] < 0 &&
759 ddata
->offsets
[SYSC_SYSSTATUS
] < 0) {
760 size
= ddata
->module_size
;
762 size
= max3(ddata
->offsets
[SYSC_REVISION
],
763 ddata
->offsets
[SYSC_SYSCONFIG
],
764 ddata
->offsets
[SYSC_SYSSTATUS
]);
769 if ((size
+ sizeof(u32
)) > ddata
->module_size
)
770 size
= ddata
->module_size
;
773 ddata
->module_va
= devm_ioremap(ddata
->dev
,
776 if (!ddata
->module_va
)
783 * sysc_map_and_check_registers - ioremap and check device registers
784 * @ddata: device driver data
786 static int sysc_map_and_check_registers(struct sysc
*ddata
)
790 error
= sysc_parse_and_check_child_range(ddata
);
794 sysc_check_children(ddata
);
796 error
= sysc_parse_registers(ddata
);
800 error
= sysc_ioremap(ddata
);
804 error
= sysc_check_registers(ddata
);
812 * sysc_show_rev - read and show interconnect target module revision
813 * @bufp: buffer to print the information to
814 * @ddata: device driver data
816 static int sysc_show_rev(char *bufp
, struct sysc
*ddata
)
820 if (ddata
->offsets
[SYSC_REVISION
] < 0)
821 return sprintf(bufp
, ":NA");
823 len
= sprintf(bufp
, ":%08x", ddata
->revision
);
828 static int sysc_show_reg(struct sysc
*ddata
,
829 char *bufp
, enum sysc_registers reg
)
831 if (ddata
->offsets
[reg
] < 0)
832 return sprintf(bufp
, ":NA");
834 return sprintf(bufp
, ":%x", ddata
->offsets
[reg
]);
837 static int sysc_show_name(char *bufp
, struct sysc
*ddata
)
842 return sprintf(bufp
, ":%s", ddata
->name
);
846 * sysc_show_registers - show information about interconnect target module
847 * @ddata: device driver data
849 static void sysc_show_registers(struct sysc
*ddata
)
855 for (i
= 0; i
< SYSC_MAX_REGS
; i
++)
856 bufp
+= sysc_show_reg(ddata
, bufp
, i
);
858 bufp
+= sysc_show_rev(bufp
, ddata
);
859 bufp
+= sysc_show_name(bufp
, ddata
);
861 dev_dbg(ddata
->dev
, "%llx:%x%s\n",
862 ddata
->module_pa
, ddata
->module_size
,
866 #define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
867 #define SYSC_CLOCACT_ICK 2
869 /* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
870 static int sysc_enable_module(struct device
*dev
)
873 const struct sysc_regbits
*regbits
;
874 u32 reg
, idlemodes
, best_mode
;
876 ddata
= dev_get_drvdata(dev
);
877 if (ddata
->offsets
[SYSC_SYSCONFIG
] == -ENODEV
)
880 regbits
= ddata
->cap
->regbits
;
881 reg
= sysc_read(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
]);
883 /* Set CLOCKACTIVITY, we only use it for ick */
884 if (regbits
->clkact_shift
>= 0 &&
885 (ddata
->cfg
.quirks
& SYSC_QUIRK_USE_CLOCKACT
||
886 ddata
->cfg
.sysc_val
& BIT(regbits
->clkact_shift
)))
887 reg
|= SYSC_CLOCACT_ICK
<< regbits
->clkact_shift
;
890 idlemodes
= ddata
->cfg
.sidlemodes
;
891 if (!idlemodes
|| regbits
->sidle_shift
< 0)
894 if (ddata
->cfg
.quirks
& (SYSC_QUIRK_SWSUP_SIDLE
|
895 SYSC_QUIRK_SWSUP_SIDLE_ACT
)) {
896 best_mode
= SYSC_IDLE_NO
;
898 best_mode
= fls(ddata
->cfg
.sidlemodes
) - 1;
899 if (best_mode
> SYSC_IDLE_MASK
) {
900 dev_err(dev
, "%s: invalid sidlemode\n", __func__
);
905 if (regbits
->enwkup_shift
>= 0 &&
906 ddata
->cfg
.sysc_val
& BIT(regbits
->enwkup_shift
))
907 reg
|= BIT(regbits
->enwkup_shift
);
910 reg
&= ~(SYSC_IDLE_MASK
<< regbits
->sidle_shift
);
911 reg
|= best_mode
<< regbits
->sidle_shift
;
912 sysc_write(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
], reg
);
916 idlemodes
= ddata
->cfg
.midlemodes
;
917 if (!idlemodes
|| regbits
->midle_shift
< 0)
920 best_mode
= fls(ddata
->cfg
.midlemodes
) - 1;
921 if (best_mode
> SYSC_IDLE_MASK
) {
922 dev_err(dev
, "%s: invalid midlemode\n", __func__
);
926 if (ddata
->cfg
.quirks
& SYSC_QUIRK_SWSUP_MSTANDBY
)
927 best_mode
= SYSC_IDLE_NO
;
929 reg
&= ~(SYSC_IDLE_MASK
<< regbits
->midle_shift
);
930 reg
|= best_mode
<< regbits
->midle_shift
;
931 sysc_write(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
], reg
);
934 /* Autoidle bit must enabled separately if available */
935 if (regbits
->autoidle_shift
>= 0 &&
936 ddata
->cfg
.sysc_val
& BIT(regbits
->autoidle_shift
)) {
937 reg
|= 1 << regbits
->autoidle_shift
;
938 sysc_write(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
], reg
);
941 if (ddata
->module_enable_quirk
)
942 ddata
->module_enable_quirk(ddata
);
947 static int sysc_best_idle_mode(u32 idlemodes
, u32
*best_mode
)
949 if (idlemodes
& BIT(SYSC_IDLE_SMART_WKUP
))
950 *best_mode
= SYSC_IDLE_SMART_WKUP
;
951 else if (idlemodes
& BIT(SYSC_IDLE_SMART
))
952 *best_mode
= SYSC_IDLE_SMART
;
953 else if (idlemodes
& BIT(SYSC_IDLE_FORCE
))
954 *best_mode
= SYSC_IDLE_FORCE
;
961 /* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
962 static int sysc_disable_module(struct device
*dev
)
965 const struct sysc_regbits
*regbits
;
966 u32 reg
, idlemodes
, best_mode
;
969 ddata
= dev_get_drvdata(dev
);
970 if (ddata
->offsets
[SYSC_SYSCONFIG
] == -ENODEV
)
973 if (ddata
->module_disable_quirk
)
974 ddata
->module_disable_quirk(ddata
);
976 regbits
= ddata
->cap
->regbits
;
977 reg
= sysc_read(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
]);
980 idlemodes
= ddata
->cfg
.midlemodes
;
981 if (!idlemodes
|| regbits
->midle_shift
< 0)
984 ret
= sysc_best_idle_mode(idlemodes
, &best_mode
);
986 dev_err(dev
, "%s: invalid midlemode\n", __func__
);
990 if (ddata
->cfg
.quirks
& (SYSC_QUIRK_SWSUP_MSTANDBY
) ||
991 ddata
->cfg
.quirks
& (SYSC_QUIRK_FORCE_MSTANDBY
))
992 best_mode
= SYSC_IDLE_FORCE
;
994 reg
&= ~(SYSC_IDLE_MASK
<< regbits
->midle_shift
);
995 reg
|= best_mode
<< regbits
->midle_shift
;
996 sysc_write(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
], reg
);
1000 idlemodes
= ddata
->cfg
.sidlemodes
;
1001 if (!idlemodes
|| regbits
->sidle_shift
< 0)
1004 if (ddata
->cfg
.quirks
& SYSC_QUIRK_SWSUP_SIDLE
) {
1005 best_mode
= SYSC_IDLE_FORCE
;
1007 ret
= sysc_best_idle_mode(idlemodes
, &best_mode
);
1009 dev_err(dev
, "%s: invalid sidlemode\n", __func__
);
1014 reg
&= ~(SYSC_IDLE_MASK
<< regbits
->sidle_shift
);
1015 reg
|= best_mode
<< regbits
->sidle_shift
;
1016 if (regbits
->autoidle_shift
>= 0 &&
1017 ddata
->cfg
.sysc_val
& BIT(regbits
->autoidle_shift
))
1018 reg
|= 1 << regbits
->autoidle_shift
;
1019 sysc_write(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
], reg
);
1024 static int __maybe_unused
sysc_runtime_suspend_legacy(struct device
*dev
,
1027 struct ti_sysc_platform_data
*pdata
;
1030 pdata
= dev_get_platdata(ddata
->dev
);
1034 if (!pdata
->idle_module
)
1037 error
= pdata
->idle_module(dev
, &ddata
->cookie
);
1039 dev_err(dev
, "%s: could not idle: %i\n",
1042 reset_control_assert(ddata
->rsts
);
1047 static int __maybe_unused
sysc_runtime_resume_legacy(struct device
*dev
,
1050 struct ti_sysc_platform_data
*pdata
;
1053 pdata
= dev_get_platdata(ddata
->dev
);
1057 if (!pdata
->enable_module
)
1060 error
= pdata
->enable_module(dev
, &ddata
->cookie
);
1062 dev_err(dev
, "%s: could not enable: %i\n",
1065 reset_control_deassert(ddata
->rsts
);
1070 static int __maybe_unused
sysc_runtime_suspend(struct device
*dev
)
1075 ddata
= dev_get_drvdata(dev
);
1077 if (!ddata
->enabled
)
1080 sysc_clkdm_deny_idle(ddata
);
1082 if (ddata
->legacy_mode
) {
1083 error
= sysc_runtime_suspend_legacy(dev
, ddata
);
1085 goto err_allow_idle
;
1087 error
= sysc_disable_module(dev
);
1089 goto err_allow_idle
;
1092 sysc_disable_main_clocks(ddata
);
1094 if (sysc_opt_clks_needed(ddata
))
1095 sysc_disable_opt_clocks(ddata
);
1097 ddata
->enabled
= false;
1100 reset_control_assert(ddata
->rsts
);
1102 sysc_clkdm_allow_idle(ddata
);
1107 static int __maybe_unused
sysc_runtime_resume(struct device
*dev
)
1112 ddata
= dev_get_drvdata(dev
);
1118 sysc_clkdm_deny_idle(ddata
);
1120 if (sysc_opt_clks_needed(ddata
)) {
1121 error
= sysc_enable_opt_clocks(ddata
);
1123 goto err_allow_idle
;
1126 error
= sysc_enable_main_clocks(ddata
);
1128 goto err_opt_clocks
;
1130 reset_control_deassert(ddata
->rsts
);
1132 if (ddata
->legacy_mode
) {
1133 error
= sysc_runtime_resume_legacy(dev
, ddata
);
1135 goto err_main_clocks
;
1137 error
= sysc_enable_module(dev
);
1139 goto err_main_clocks
;
1142 ddata
->enabled
= true;
1144 sysc_clkdm_allow_idle(ddata
);
1149 sysc_disable_main_clocks(ddata
);
1151 if (sysc_opt_clks_needed(ddata
))
1152 sysc_disable_opt_clocks(ddata
);
1154 sysc_clkdm_allow_idle(ddata
);
1159 static int __maybe_unused
sysc_noirq_suspend(struct device
*dev
)
1163 ddata
= dev_get_drvdata(dev
);
1165 if (ddata
->cfg
.quirks
& SYSC_QUIRK_LEGACY_IDLE
)
1168 return pm_runtime_force_suspend(dev
);
1171 static int __maybe_unused
sysc_noirq_resume(struct device
*dev
)
1175 ddata
= dev_get_drvdata(dev
);
1177 if (ddata
->cfg
.quirks
& SYSC_QUIRK_LEGACY_IDLE
)
1180 return pm_runtime_force_resume(dev
);
1183 static const struct dev_pm_ops sysc_pm_ops
= {
1184 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend
, sysc_noirq_resume
)
1185 SET_RUNTIME_PM_OPS(sysc_runtime_suspend
,
1186 sysc_runtime_resume
,
1190 /* Module revision register based quirks */
1191 struct sysc_revision_quirk
{
1202 #define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1203 optrev_val, optrevmask, optquirkmask) \
1205 .name = (optname), \
1206 .base = (optbase), \
1207 .rev_offset = (optrev), \
1208 .sysc_offset = (optsysc), \
1209 .syss_offset = (optsyss), \
1210 .revision = (optrev_val), \
1211 .revision_mask = (optrevmask), \
1212 .quirks = (optquirkmask), \
1215 static const struct sysc_revision_quirk sysc_revision_quirks
[] = {
1216 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
1217 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
1218 SYSC_QUIRK_LEGACY_IDLE
| SYSC_QUIRK_OPT_CLKS_IN_RESET
),
1219 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
1220 SYSC_QUIRK_LEGACY_IDLE
),
1221 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff,
1222 SYSC_QUIRK_LEGACY_IDLE
),
1223 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1224 SYSC_QUIRK_LEGACY_IDLE
),
1225 SYSC_QUIRK("smartreflex", 0, -1, 0x24, -1, 0x00000000, 0xffffffff,
1226 SYSC_QUIRK_LEGACY_IDLE
),
1227 SYSC_QUIRK("smartreflex", 0, -1, 0x38, -1, 0x00000000, 0xffffffff,
1228 SYSC_QUIRK_LEGACY_IDLE
),
1229 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff,
1231 /* Some timers on omap4 and later */
1232 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x50002100, 0xffffffff,
1234 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x4fff1301, 0xffff00ff,
1236 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1237 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_LEGACY_IDLE
),
1238 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
1239 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_LEGACY_IDLE
),
1240 /* Uarts on omap4 and later */
1241 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
1242 SYSC_QUIRK_SWSUP_SIDLE_ACT
| SYSC_QUIRK_LEGACY_IDLE
),
1243 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
1244 SYSC_QUIRK_SWSUP_SIDLE_ACT
| SYSC_QUIRK_LEGACY_IDLE
),
1246 /* Quirks that need to be set based on the module address */
1247 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -1, 0x50000800, 0xffffffff,
1248 SYSC_QUIRK_EXT_OPT_CLOCK
| SYSC_QUIRK_NO_RESET_ON_INIT
|
1249 SYSC_QUIRK_SWSUP_SIDLE
),
1251 /* Quirks that need to be set based on detected module */
1252 SYSC_QUIRK("aess", 0, 0, 0x10, -1, 0x40000000, 0xffffffff,
1253 SYSC_MODULE_QUIRK_AESS
),
1254 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
1255 SYSC_MODULE_QUIRK_HDQ1W
),
1256 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
1257 SYSC_MODULE_QUIRK_HDQ1W
),
1258 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
1259 SYSC_MODULE_QUIRK_I2C
),
1260 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
1261 SYSC_MODULE_QUIRK_I2C
),
1262 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
1263 SYSC_MODULE_QUIRK_I2C
),
1264 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
1265 SYSC_MODULE_QUIRK_I2C
),
1266 SYSC_QUIRK("gpu", 0x50000000, 0x14, -1, -1, 0x00010201, 0xffffffff, 0),
1267 SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -1, 0x40000000 , 0xffffffff,
1268 SYSC_MODULE_QUIRK_SGX
),
1269 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1270 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_SWSUP_MSTANDBY
),
1271 SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -1, 0x4ea2080d, 0xffffffff,
1272 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_SWSUP_MSTANDBY
),
1273 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1274 SYSC_MODULE_QUIRK_WDT
),
1275 /* Watchdog on am3 and am4 */
1276 SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1277 SYSC_MODULE_QUIRK_WDT
| SYSC_QUIRK_SWSUP_SIDLE
),
1280 SYSC_QUIRK("adc", 0, 0, 0x10, -1, 0x47300001, 0xffffffff, 0),
1281 SYSC_QUIRK("atl", 0, 0, -1, -1, 0x0a070100, 0xffffffff, 0),
1282 SYSC_QUIRK("cm", 0, 0, -1, -1, 0x40000301, 0xffffffff, 0),
1283 SYSC_QUIRK("control", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
1284 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
1286 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0xa3170504, 0xffffffff, 0),
1287 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0x4edb1902, 0xffffffff, 0),
1288 SYSC_QUIRK("dmic", 0, 0, 0x10, -1, 0x50010000, 0xffffffff, 0),
1289 SYSC_QUIRK("dwc3", 0, 0, 0x10, -1, 0x500a0200, 0xffffffff, 0),
1290 SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1291 SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1292 SYSC_QUIRK("epwmss", 0, 0, 0x4, -1, 0x47400001, 0xffffffff, 0),
1293 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -1, 0, 0, 0),
1294 SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -1, 0x40000000 , 0xffffffff, 0),
1295 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
1296 SYSC_QUIRK("iss", 0, 0, 0x10, -1, 0x40000101, 0xffffffff, 0),
1297 SYSC_QUIRK("lcdc", 0, 0, 0x54, -1, 0x4f201000, 0xffffffff, 0),
1298 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44306302, 0xffffffff, 0),
1299 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44307b02, 0xffffffff, 0),
1300 SYSC_QUIRK("mcbsp", 0, -1, 0x8c, -1, 0, 0, 0),
1301 SYSC_QUIRK("mcspi", 0, 0, 0x10, -1, 0x40300a0b, 0xffff00ff, 0),
1302 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
1303 SYSC_QUIRK("mailbox", 0, 0, 0x10, -1, 0x00000400, 0xffffffff, 0),
1304 SYSC_QUIRK("m3", 0, 0, -1, -1, 0x5f580105, 0x0fff0f00, 0),
1305 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
1306 SYSC_QUIRK("ocp2scp", 0, 0, -1, -1, 0x50060007, 0xffffffff, 0),
1307 SYSC_QUIRK("padconf", 0, 0, 0x10, -1, 0x4fff0800, 0xffffffff, 0),
1308 SYSC_QUIRK("padconf", 0, 0, -1, -1, 0x40001100, 0xffffffff, 0),
1309 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000100, 0xffffffff, 0),
1310 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x00004102, 0xffffffff, 0),
1311 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000400, 0xffffffff, 0),
1312 SYSC_QUIRK("scm", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
1313 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4e8b0100, 0xffffffff, 0),
1314 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4f000100, 0xffffffff, 0),
1315 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x40000900, 0xffffffff, 0),
1316 SYSC_QUIRK("scrm", 0, 0, -1, -1, 0x00000010, 0xffffffff, 0),
1317 SYSC_QUIRK("sdio", 0, 0, 0x10, -1, 0x40202301, 0xffff0ff0, 0),
1318 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
1319 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
1320 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40000902, 0xffffffff, 0),
1321 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40002903, 0xffffffff, 0),
1322 SYSC_QUIRK("spinlock", 0, 0, 0x10, -1, 0x50020000, 0xffffffff, 0),
1323 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -1, 0x00000020, 0xffffffff, 0),
1324 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -1, 0x4eb01908, 0xffff00f0, 0),
1325 SYSC_QUIRK("timer32k", 0, 0, 0x4, -1, 0x00000060, 0xffffffff, 0),
1326 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
1327 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
1328 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, 0),
1329 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -1, 0x50700101, 0xffffffff, 0),
1330 SYSC_QUIRK("vfpe", 0, 0, 0x104, -1, 0x4d001200, 0xffffffff, 0),
1335 * Early quirks based on module base and register offsets only that are
1336 * needed before the module revision can be read
1338 static void sysc_init_early_quirks(struct sysc
*ddata
)
1340 const struct sysc_revision_quirk
*q
;
1343 for (i
= 0; i
< ARRAY_SIZE(sysc_revision_quirks
); i
++) {
1344 q
= &sysc_revision_quirks
[i
];
1349 if (q
->base
!= ddata
->module_pa
)
1352 if (q
->rev_offset
>= 0 &&
1353 q
->rev_offset
!= ddata
->offsets
[SYSC_REVISION
])
1356 if (q
->sysc_offset
>= 0 &&
1357 q
->sysc_offset
!= ddata
->offsets
[SYSC_SYSCONFIG
])
1360 if (q
->syss_offset
>= 0 &&
1361 q
->syss_offset
!= ddata
->offsets
[SYSC_SYSSTATUS
])
1364 ddata
->name
= q
->name
;
1365 ddata
->cfg
.quirks
|= q
->quirks
;
1369 /* Quirks that also consider the revision register value */
1370 static void sysc_init_revision_quirks(struct sysc
*ddata
)
1372 const struct sysc_revision_quirk
*q
;
1375 for (i
= 0; i
< ARRAY_SIZE(sysc_revision_quirks
); i
++) {
1376 q
= &sysc_revision_quirks
[i
];
1378 if (q
->base
&& q
->base
!= ddata
->module_pa
)
1381 if (q
->rev_offset
>= 0 &&
1382 q
->rev_offset
!= ddata
->offsets
[SYSC_REVISION
])
1385 if (q
->sysc_offset
>= 0 &&
1386 q
->sysc_offset
!= ddata
->offsets
[SYSC_SYSCONFIG
])
1389 if (q
->syss_offset
>= 0 &&
1390 q
->syss_offset
!= ddata
->offsets
[SYSC_SYSSTATUS
])
1393 if (q
->revision
== ddata
->revision
||
1394 (q
->revision
& q
->revision_mask
) ==
1395 (ddata
->revision
& q
->revision_mask
)) {
1396 ddata
->name
= q
->name
;
1397 ddata
->cfg
.quirks
|= q
->quirks
;
1402 /* 1-wire needs module's internal clocks enabled for reset */
1403 static void sysc_clk_enable_quirk_hdq1w(struct sysc
*ddata
)
1405 int offset
= 0x0c; /* HDQ_CTRL_STATUS */
1408 val
= sysc_read(ddata
, offset
);
1410 sysc_write(ddata
, offset
, val
);
1413 /* AESS (Audio Engine SubSystem) needs autogating set after enable */
1414 static void sysc_module_enable_quirk_aess(struct sysc
*ddata
)
1416 int offset
= 0x7c; /* AESS_AUTO_GATING_ENABLE */
1418 sysc_write(ddata
, offset
, 1);
1421 /* I2C needs extra enable bit toggling for reset */
1422 static void sysc_clk_quirk_i2c(struct sysc
*ddata
, bool enable
)
1427 /* I2C_CON, omap2/3 is different from omap4 and later */
1428 if ((ddata
->revision
& 0xffffff00) == 0x001f0000)
1434 val
= sysc_read(ddata
, offset
);
1439 sysc_write(ddata
, offset
, val
);
1442 static void sysc_clk_enable_quirk_i2c(struct sysc
*ddata
)
1444 sysc_clk_quirk_i2c(ddata
, true);
1447 static void sysc_clk_disable_quirk_i2c(struct sysc
*ddata
)
1449 sysc_clk_quirk_i2c(ddata
, false);
1452 /* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */
1453 static void sysc_module_enable_quirk_sgx(struct sysc
*ddata
)
1455 int offset
= 0xff08; /* OCP_DEBUG_CONFIG */
1456 u32 val
= BIT(31); /* THALIA_INT_BYPASS */
1458 sysc_write(ddata
, offset
, val
);
1461 /* Watchdog timer needs a disable sequence after reset */
1462 static void sysc_reset_done_quirk_wdt(struct sysc
*ddata
)
1464 int wps
, spr
, error
;
1470 sysc_write(ddata
, spr
, 0xaaaa);
1471 error
= readl_poll_timeout(ddata
->module_va
+ wps
, val
,
1473 MAX_MODULE_SOFTRESET_WAIT
);
1475 dev_warn(ddata
->dev
, "wdt disable step1 failed\n");
1477 sysc_write(ddata
, spr
, 0x5555);
1478 error
= readl_poll_timeout(ddata
->module_va
+ wps
, val
,
1480 MAX_MODULE_SOFTRESET_WAIT
);
1482 dev_warn(ddata
->dev
, "wdt disable step2 failed\n");
1485 static void sysc_init_module_quirks(struct sysc
*ddata
)
1487 if (ddata
->legacy_mode
|| !ddata
->name
)
1490 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_HDQ1W
) {
1491 ddata
->clk_enable_quirk
= sysc_clk_enable_quirk_hdq1w
;
1496 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_I2C
) {
1497 ddata
->clk_enable_quirk
= sysc_clk_enable_quirk_i2c
;
1498 ddata
->clk_disable_quirk
= sysc_clk_disable_quirk_i2c
;
1503 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_AESS
)
1504 ddata
->module_enable_quirk
= sysc_module_enable_quirk_aess
;
1506 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_SGX
)
1507 ddata
->module_enable_quirk
= sysc_module_enable_quirk_sgx
;
1509 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_WDT
) {
1510 ddata
->reset_done_quirk
= sysc_reset_done_quirk_wdt
;
1511 ddata
->module_disable_quirk
= sysc_reset_done_quirk_wdt
;
1515 static int sysc_clockdomain_init(struct sysc
*ddata
)
1517 struct ti_sysc_platform_data
*pdata
= dev_get_platdata(ddata
->dev
);
1518 struct clk
*fck
= NULL
, *ick
= NULL
;
1521 if (!pdata
|| !pdata
->init_clockdomain
)
1524 switch (ddata
->nr_clocks
) {
1526 ick
= ddata
->clocks
[SYSC_ICK
];
1529 fck
= ddata
->clocks
[SYSC_FCK
];
1535 error
= pdata
->init_clockdomain(ddata
->dev
, fck
, ick
, &ddata
->cookie
);
1536 if (!error
|| error
== -ENODEV
)
1543 * Note that pdata->init_module() typically does a reset first. After
1544 * pdata->init_module() is done, PM runtime can be used for the interconnect
1547 static int sysc_legacy_init(struct sysc
*ddata
)
1549 struct ti_sysc_platform_data
*pdata
= dev_get_platdata(ddata
->dev
);
1552 if (!pdata
|| !pdata
->init_module
)
1555 error
= pdata
->init_module(ddata
->dev
, ddata
->mdata
, &ddata
->cookie
);
1556 if (error
== -EEXIST
)
1563 * Note that the caller must ensure the interconnect target module is enabled
1564 * before calling reset. Otherwise reset will not complete.
1566 static int sysc_reset(struct sysc
*ddata
)
1568 int sysc_offset
, syss_offset
, sysc_val
, rstval
, error
= 0;
1569 u32 sysc_mask
, syss_done
;
1571 sysc_offset
= ddata
->offsets
[SYSC_SYSCONFIG
];
1572 syss_offset
= ddata
->offsets
[SYSC_SYSSTATUS
];
1574 if (ddata
->legacy_mode
|| sysc_offset
< 0 ||
1575 ddata
->cap
->regbits
->srst_shift
< 0 ||
1576 ddata
->cfg
.quirks
& SYSC_QUIRK_NO_RESET_ON_INIT
)
1579 sysc_mask
= BIT(ddata
->cap
->regbits
->srst_shift
);
1581 if (ddata
->cfg
.quirks
& SYSS_QUIRK_RESETDONE_INVERTED
)
1584 syss_done
= ddata
->cfg
.syss_mask
;
1586 if (ddata
->clk_disable_quirk
)
1587 ddata
->clk_disable_quirk(ddata
);
1589 sysc_val
= sysc_read_sysconfig(ddata
);
1590 sysc_val
|= sysc_mask
;
1591 sysc_write(ddata
, sysc_offset
, sysc_val
);
1593 if (ddata
->cfg
.srst_udelay
)
1594 usleep_range(ddata
->cfg
.srst_udelay
,
1595 ddata
->cfg
.srst_udelay
* 2);
1597 if (ddata
->clk_enable_quirk
)
1598 ddata
->clk_enable_quirk(ddata
);
1600 /* Poll on reset status */
1601 if (syss_offset
>= 0) {
1602 error
= readx_poll_timeout(sysc_read_sysstatus
, ddata
, rstval
,
1603 (rstval
& ddata
->cfg
.syss_mask
) ==
1605 100, MAX_MODULE_SOFTRESET_WAIT
);
1607 } else if (ddata
->cfg
.quirks
& SYSC_QUIRK_RESET_STATUS
) {
1608 error
= readx_poll_timeout(sysc_read_sysconfig
, ddata
, rstval
,
1609 !(rstval
& sysc_mask
),
1610 100, MAX_MODULE_SOFTRESET_WAIT
);
1613 if (ddata
->reset_done_quirk
)
1614 ddata
->reset_done_quirk(ddata
);
1620 * At this point the module is configured enough to read the revision but
1621 * module may not be completely configured yet to use PM runtime. Enable
1622 * all clocks directly during init to configure the quirks needed for PM
1623 * runtime based on the revision register.
1625 static int sysc_init_module(struct sysc
*ddata
)
1629 error
= sysc_clockdomain_init(ddata
);
1633 sysc_clkdm_deny_idle(ddata
);
1636 * Always enable clocks. The bootloader may or may not have enabled
1637 * the related clocks.
1639 error
= sysc_enable_opt_clocks(ddata
);
1643 error
= sysc_enable_main_clocks(ddata
);
1645 goto err_opt_clocks
;
1647 if (!(ddata
->cfg
.quirks
& SYSC_QUIRK_NO_RESET_ON_INIT
)) {
1648 error
= reset_control_deassert(ddata
->rsts
);
1650 goto err_main_clocks
;
1653 ddata
->revision
= sysc_read_revision(ddata
);
1654 sysc_init_revision_quirks(ddata
);
1655 sysc_init_module_quirks(ddata
);
1657 if (ddata
->legacy_mode
) {
1658 error
= sysc_legacy_init(ddata
);
1663 if (!ddata
->legacy_mode
) {
1664 error
= sysc_enable_module(ddata
->dev
);
1669 error
= sysc_reset(ddata
);
1671 dev_err(ddata
->dev
, "Reset failed with %d\n", error
);
1673 if (error
&& !ddata
->legacy_mode
)
1674 sysc_disable_module(ddata
->dev
);
1677 if (error
&& !(ddata
->cfg
.quirks
& SYSC_QUIRK_NO_RESET_ON_INIT
))
1678 reset_control_assert(ddata
->rsts
);
1682 sysc_disable_main_clocks(ddata
);
1684 /* No re-enable of clockdomain autoidle to prevent module autoidle */
1686 sysc_disable_opt_clocks(ddata
);
1687 sysc_clkdm_allow_idle(ddata
);
1693 static int sysc_init_sysc_mask(struct sysc
*ddata
)
1695 struct device_node
*np
= ddata
->dev
->of_node
;
1699 error
= of_property_read_u32(np
, "ti,sysc-mask", &val
);
1703 ddata
->cfg
.sysc_val
= val
& ddata
->cap
->sysc_mask
;
1708 static int sysc_init_idlemode(struct sysc
*ddata
, u8
*idlemodes
,
1711 struct device_node
*np
= ddata
->dev
->of_node
;
1712 struct property
*prop
;
1716 of_property_for_each_u32(np
, name
, prop
, p
, val
) {
1717 if (val
>= SYSC_NR_IDLEMODES
) {
1718 dev_err(ddata
->dev
, "invalid idlemode: %i\n", val
);
1721 *idlemodes
|= (1 << val
);
1727 static int sysc_init_idlemodes(struct sysc
*ddata
)
1731 error
= sysc_init_idlemode(ddata
, &ddata
->cfg
.midlemodes
,
1736 error
= sysc_init_idlemode(ddata
, &ddata
->cfg
.sidlemodes
,
1745 * Only some devices on omap4 and later have SYSCONFIG reset done
1746 * bit. We can detect this if there is no SYSSTATUS at all, or the
1747 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
1748 * have multiple bits for the child devices like OHCI and EHCI.
1749 * Depends on SYSC being parsed first.
1751 static int sysc_init_syss_mask(struct sysc
*ddata
)
1753 struct device_node
*np
= ddata
->dev
->of_node
;
1757 error
= of_property_read_u32(np
, "ti,syss-mask", &val
);
1759 if ((ddata
->cap
->type
== TI_SYSC_OMAP4
||
1760 ddata
->cap
->type
== TI_SYSC_OMAP4_TIMER
) &&
1761 (ddata
->cfg
.sysc_val
& SYSC_OMAP4_SOFTRESET
))
1762 ddata
->cfg
.quirks
|= SYSC_QUIRK_RESET_STATUS
;
1767 if (!(val
& 1) && (ddata
->cfg
.sysc_val
& SYSC_OMAP4_SOFTRESET
))
1768 ddata
->cfg
.quirks
|= SYSC_QUIRK_RESET_STATUS
;
1770 ddata
->cfg
.syss_mask
= val
;
1776 * Many child device drivers need to have fck and opt clocks available
1777 * to get the clock rate for device internal configuration etc.
1779 static int sysc_child_add_named_clock(struct sysc
*ddata
,
1780 struct device
*child
,
1784 struct clk_lookup
*l
;
1790 clk
= clk_get(child
, name
);
1796 clk
= clk_get(ddata
->dev
, name
);
1800 l
= clkdev_create(clk
, name
, dev_name(child
));
1809 static int sysc_child_add_clocks(struct sysc
*ddata
,
1810 struct device
*child
)
1814 for (i
= 0; i
< ddata
->nr_clocks
; i
++) {
1815 error
= sysc_child_add_named_clock(ddata
,
1817 ddata
->clock_roles
[i
]);
1818 if (error
&& error
!= -EEXIST
) {
1819 dev_err(ddata
->dev
, "could not add child clock %s: %i\n",
1820 ddata
->clock_roles
[i
], error
);
1829 static struct device_type sysc_device_type
= {
1832 static struct sysc
*sysc_child_to_parent(struct device
*dev
)
1834 struct device
*parent
= dev
->parent
;
1836 if (!parent
|| parent
->type
!= &sysc_device_type
)
1839 return dev_get_drvdata(parent
);
1842 static int __maybe_unused
sysc_child_runtime_suspend(struct device
*dev
)
1847 ddata
= sysc_child_to_parent(dev
);
1849 error
= pm_generic_runtime_suspend(dev
);
1853 if (!ddata
->enabled
)
1856 return sysc_runtime_suspend(ddata
->dev
);
1859 static int __maybe_unused
sysc_child_runtime_resume(struct device
*dev
)
1864 ddata
= sysc_child_to_parent(dev
);
1866 if (!ddata
->enabled
) {
1867 error
= sysc_runtime_resume(ddata
->dev
);
1870 "%s error: %i\n", __func__
, error
);
1873 return pm_generic_runtime_resume(dev
);
1876 #ifdef CONFIG_PM_SLEEP
1877 static int sysc_child_suspend_noirq(struct device
*dev
)
1882 ddata
= sysc_child_to_parent(dev
);
1884 dev_dbg(ddata
->dev
, "%s %s\n", __func__
,
1885 ddata
->name
? ddata
->name
: "");
1887 error
= pm_generic_suspend_noirq(dev
);
1889 dev_err(dev
, "%s error at %i: %i\n",
1890 __func__
, __LINE__
, error
);
1895 if (!pm_runtime_status_suspended(dev
)) {
1896 error
= pm_generic_runtime_suspend(dev
);
1898 dev_dbg(dev
, "%s busy at %i: %i\n",
1899 __func__
, __LINE__
, error
);
1904 error
= sysc_runtime_suspend(ddata
->dev
);
1906 dev_err(dev
, "%s error at %i: %i\n",
1907 __func__
, __LINE__
, error
);
1912 ddata
->child_needs_resume
= true;
1918 static int sysc_child_resume_noirq(struct device
*dev
)
1923 ddata
= sysc_child_to_parent(dev
);
1925 dev_dbg(ddata
->dev
, "%s %s\n", __func__
,
1926 ddata
->name
? ddata
->name
: "");
1928 if (ddata
->child_needs_resume
) {
1929 ddata
->child_needs_resume
= false;
1931 error
= sysc_runtime_resume(ddata
->dev
);
1934 "%s runtime resume error: %i\n",
1937 error
= pm_generic_runtime_resume(dev
);
1940 "%s generic runtime resume: %i\n",
1944 return pm_generic_resume_noirq(dev
);
1948 static struct dev_pm_domain sysc_child_pm_domain
= {
1950 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend
,
1951 sysc_child_runtime_resume
,
1953 USE_PLATFORM_PM_SLEEP_OPS
1954 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq
,
1955 sysc_child_resume_noirq
)
1960 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
1961 * @ddata: device driver data
1962 * @child: child device driver
1964 * Allow idle for child devices as done with _od_runtime_suspend().
1965 * Otherwise many child devices will not idle because of the permanent
1966 * parent usecount set in pm_runtime_irq_safe().
1968 * Note that the long term solution is to just modify the child device
1969 * drivers to not set pm_runtime_irq_safe() and then this can be just
1972 static void sysc_legacy_idle_quirk(struct sysc
*ddata
, struct device
*child
)
1974 if (ddata
->cfg
.quirks
& SYSC_QUIRK_LEGACY_IDLE
)
1975 dev_pm_domain_set(child
, &sysc_child_pm_domain
);
1978 static int sysc_notifier_call(struct notifier_block
*nb
,
1979 unsigned long event
, void *device
)
1981 struct device
*dev
= device
;
1985 ddata
= sysc_child_to_parent(dev
);
1990 case BUS_NOTIFY_ADD_DEVICE
:
1991 error
= sysc_child_add_clocks(ddata
, dev
);
1994 sysc_legacy_idle_quirk(ddata
, dev
);
2003 static struct notifier_block sysc_nb
= {
2004 .notifier_call
= sysc_notifier_call
,
2007 /* Device tree configured quirks */
2008 struct sysc_dts_quirk
{
2013 static const struct sysc_dts_quirk sysc_dts_quirks
[] = {
2014 { .name
= "ti,no-idle-on-init",
2015 .mask
= SYSC_QUIRK_NO_IDLE_ON_INIT
, },
2016 { .name
= "ti,no-reset-on-init",
2017 .mask
= SYSC_QUIRK_NO_RESET_ON_INIT
, },
2018 { .name
= "ti,no-idle",
2019 .mask
= SYSC_QUIRK_NO_IDLE
, },
2022 static void sysc_parse_dts_quirks(struct sysc
*ddata
, struct device_node
*np
,
2025 const struct property
*prop
;
2028 for (i
= 0; i
< ARRAY_SIZE(sysc_dts_quirks
); i
++) {
2029 const char *name
= sysc_dts_quirks
[i
].name
;
2031 prop
= of_get_property(np
, name
, &len
);
2035 ddata
->cfg
.quirks
|= sysc_dts_quirks
[i
].mask
;
2037 dev_warn(ddata
->dev
,
2038 "dts flag should be at module level for %s\n",
2044 static int sysc_init_dts_quirks(struct sysc
*ddata
)
2046 struct device_node
*np
= ddata
->dev
->of_node
;
2050 ddata
->legacy_mode
= of_get_property(np
, "ti,hwmods", NULL
);
2052 sysc_parse_dts_quirks(ddata
, np
, false);
2053 error
= of_property_read_u32(np
, "ti,sysc-delay-us", &val
);
2056 dev_warn(ddata
->dev
, "bad ti,sysc-delay-us: %i\n",
2060 ddata
->cfg
.srst_udelay
= (u8
)val
;
2066 static void sysc_unprepare(struct sysc
*ddata
)
2073 for (i
= 0; i
< SYSC_MAX_CLOCKS
; i
++) {
2074 if (!IS_ERR_OR_NULL(ddata
->clocks
[i
]))
2075 clk_unprepare(ddata
->clocks
[i
]);
2080 * Common sysc register bits found on omap2, also known as type1
2082 static const struct sysc_regbits sysc_regbits_omap2
= {
2083 .dmadisable_shift
= -ENODEV
,
2090 .autoidle_shift
= 0,
2093 static const struct sysc_capabilities sysc_omap2
= {
2094 .type
= TI_SYSC_OMAP2
,
2095 .sysc_mask
= SYSC_OMAP2_CLOCKACTIVITY
| SYSC_OMAP2_EMUFREE
|
2096 SYSC_OMAP2_ENAWAKEUP
| SYSC_OMAP2_SOFTRESET
|
2097 SYSC_OMAP2_AUTOIDLE
,
2098 .regbits
= &sysc_regbits_omap2
,
2101 /* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2102 static const struct sysc_capabilities sysc_omap2_timer
= {
2103 .type
= TI_SYSC_OMAP2_TIMER
,
2104 .sysc_mask
= SYSC_OMAP2_CLOCKACTIVITY
| SYSC_OMAP2_EMUFREE
|
2105 SYSC_OMAP2_ENAWAKEUP
| SYSC_OMAP2_SOFTRESET
|
2106 SYSC_OMAP2_AUTOIDLE
,
2107 .regbits
= &sysc_regbits_omap2
,
2108 .mod_quirks
= SYSC_QUIRK_USE_CLOCKACT
,
2112 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2113 * with different sidle position
2115 static const struct sysc_regbits sysc_regbits_omap3_sham
= {
2116 .dmadisable_shift
= -ENODEV
,
2117 .midle_shift
= -ENODEV
,
2119 .clkact_shift
= -ENODEV
,
2120 .enwkup_shift
= -ENODEV
,
2122 .autoidle_shift
= 0,
2123 .emufree_shift
= -ENODEV
,
2126 static const struct sysc_capabilities sysc_omap3_sham
= {
2127 .type
= TI_SYSC_OMAP3_SHAM
,
2128 .sysc_mask
= SYSC_OMAP2_SOFTRESET
| SYSC_OMAP2_AUTOIDLE
,
2129 .regbits
= &sysc_regbits_omap3_sham
,
2133 * AES register bits found on omap3 and later, a variant of
2134 * sysc_regbits_omap2 with different sidle position
2136 static const struct sysc_regbits sysc_regbits_omap3_aes
= {
2137 .dmadisable_shift
= -ENODEV
,
2138 .midle_shift
= -ENODEV
,
2140 .clkact_shift
= -ENODEV
,
2141 .enwkup_shift
= -ENODEV
,
2143 .autoidle_shift
= 0,
2144 .emufree_shift
= -ENODEV
,
2147 static const struct sysc_capabilities sysc_omap3_aes
= {
2148 .type
= TI_SYSC_OMAP3_AES
,
2149 .sysc_mask
= SYSC_OMAP2_SOFTRESET
| SYSC_OMAP2_AUTOIDLE
,
2150 .regbits
= &sysc_regbits_omap3_aes
,
2154 * Common sysc register bits found on omap4, also known as type2
2156 static const struct sysc_regbits sysc_regbits_omap4
= {
2157 .dmadisable_shift
= 16,
2160 .clkact_shift
= -ENODEV
,
2161 .enwkup_shift
= -ENODEV
,
2164 .autoidle_shift
= -ENODEV
,
2167 static const struct sysc_capabilities sysc_omap4
= {
2168 .type
= TI_SYSC_OMAP4
,
2169 .sysc_mask
= SYSC_OMAP4_DMADISABLE
| SYSC_OMAP4_FREEEMU
|
2170 SYSC_OMAP4_SOFTRESET
,
2171 .regbits
= &sysc_regbits_omap4
,
2174 static const struct sysc_capabilities sysc_omap4_timer
= {
2175 .type
= TI_SYSC_OMAP4_TIMER
,
2176 .sysc_mask
= SYSC_OMAP4_DMADISABLE
| SYSC_OMAP4_FREEEMU
|
2177 SYSC_OMAP4_SOFTRESET
,
2178 .regbits
= &sysc_regbits_omap4
,
2182 * Common sysc register bits found on omap4, also known as type3
2184 static const struct sysc_regbits sysc_regbits_omap4_simple
= {
2185 .dmadisable_shift
= -ENODEV
,
2188 .clkact_shift
= -ENODEV
,
2189 .enwkup_shift
= -ENODEV
,
2190 .srst_shift
= -ENODEV
,
2191 .emufree_shift
= -ENODEV
,
2192 .autoidle_shift
= -ENODEV
,
2195 static const struct sysc_capabilities sysc_omap4_simple
= {
2196 .type
= TI_SYSC_OMAP4_SIMPLE
,
2197 .regbits
= &sysc_regbits_omap4_simple
,
2201 * SmartReflex sysc found on omap34xx
2203 static const struct sysc_regbits sysc_regbits_omap34xx_sr
= {
2204 .dmadisable_shift
= -ENODEV
,
2205 .midle_shift
= -ENODEV
,
2206 .sidle_shift
= -ENODEV
,
2208 .enwkup_shift
= -ENODEV
,
2209 .srst_shift
= -ENODEV
,
2210 .emufree_shift
= -ENODEV
,
2211 .autoidle_shift
= -ENODEV
,
2214 static const struct sysc_capabilities sysc_34xx_sr
= {
2215 .type
= TI_SYSC_OMAP34XX_SR
,
2216 .sysc_mask
= SYSC_OMAP2_CLOCKACTIVITY
,
2217 .regbits
= &sysc_regbits_omap34xx_sr
,
2218 .mod_quirks
= SYSC_QUIRK_USE_CLOCKACT
| SYSC_QUIRK_UNCACHED
|
2219 SYSC_QUIRK_LEGACY_IDLE
,
2223 * SmartReflex sysc found on omap36xx and later
2225 static const struct sysc_regbits sysc_regbits_omap36xx_sr
= {
2226 .dmadisable_shift
= -ENODEV
,
2227 .midle_shift
= -ENODEV
,
2229 .clkact_shift
= -ENODEV
,
2231 .srst_shift
= -ENODEV
,
2232 .emufree_shift
= -ENODEV
,
2233 .autoidle_shift
= -ENODEV
,
2236 static const struct sysc_capabilities sysc_36xx_sr
= {
2237 .type
= TI_SYSC_OMAP36XX_SR
,
2238 .sysc_mask
= SYSC_OMAP3_SR_ENAWAKEUP
,
2239 .regbits
= &sysc_regbits_omap36xx_sr
,
2240 .mod_quirks
= SYSC_QUIRK_UNCACHED
| SYSC_QUIRK_LEGACY_IDLE
,
2243 static const struct sysc_capabilities sysc_omap4_sr
= {
2244 .type
= TI_SYSC_OMAP4_SR
,
2245 .regbits
= &sysc_regbits_omap36xx_sr
,
2246 .mod_quirks
= SYSC_QUIRK_LEGACY_IDLE
,
2250 * McASP register bits found on omap4 and later
2252 static const struct sysc_regbits sysc_regbits_omap4_mcasp
= {
2253 .dmadisable_shift
= -ENODEV
,
2254 .midle_shift
= -ENODEV
,
2256 .clkact_shift
= -ENODEV
,
2257 .enwkup_shift
= -ENODEV
,
2258 .srst_shift
= -ENODEV
,
2259 .emufree_shift
= -ENODEV
,
2260 .autoidle_shift
= -ENODEV
,
2263 static const struct sysc_capabilities sysc_omap4_mcasp
= {
2264 .type
= TI_SYSC_OMAP4_MCASP
,
2265 .regbits
= &sysc_regbits_omap4_mcasp
,
2266 .mod_quirks
= SYSC_QUIRK_OPT_CLKS_NEEDED
,
2270 * McASP found on dra7 and later
2272 static const struct sysc_capabilities sysc_dra7_mcasp
= {
2273 .type
= TI_SYSC_OMAP4_SIMPLE
,
2274 .regbits
= &sysc_regbits_omap4_simple
,
2275 .mod_quirks
= SYSC_QUIRK_OPT_CLKS_NEEDED
,
2279 * FS USB host found on omap4 and later
2281 static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs
= {
2282 .dmadisable_shift
= -ENODEV
,
2283 .midle_shift
= -ENODEV
,
2285 .clkact_shift
= -ENODEV
,
2287 .srst_shift
= -ENODEV
,
2288 .emufree_shift
= -ENODEV
,
2289 .autoidle_shift
= -ENODEV
,
2292 static const struct sysc_capabilities sysc_omap4_usb_host_fs
= {
2293 .type
= TI_SYSC_OMAP4_USB_HOST_FS
,
2294 .sysc_mask
= SYSC_OMAP2_ENAWAKEUP
,
2295 .regbits
= &sysc_regbits_omap4_usb_host_fs
,
2298 static const struct sysc_regbits sysc_regbits_dra7_mcan
= {
2299 .dmadisable_shift
= -ENODEV
,
2300 .midle_shift
= -ENODEV
,
2301 .sidle_shift
= -ENODEV
,
2302 .clkact_shift
= -ENODEV
,
2305 .emufree_shift
= -ENODEV
,
2306 .autoidle_shift
= -ENODEV
,
2309 static const struct sysc_capabilities sysc_dra7_mcan
= {
2310 .type
= TI_SYSC_DRA7_MCAN
,
2311 .sysc_mask
= SYSC_DRA7_MCAN_ENAWAKEUP
| SYSC_OMAP4_SOFTRESET
,
2312 .regbits
= &sysc_regbits_dra7_mcan
,
2313 .mod_quirks
= SYSS_QUIRK_RESETDONE_INVERTED
,
2316 static int sysc_init_pdata(struct sysc
*ddata
)
2318 struct ti_sysc_platform_data
*pdata
= dev_get_platdata(ddata
->dev
);
2319 struct ti_sysc_module_data
*mdata
;
2324 mdata
= devm_kzalloc(ddata
->dev
, sizeof(*mdata
), GFP_KERNEL
);
2328 if (ddata
->legacy_mode
) {
2329 mdata
->name
= ddata
->legacy_mode
;
2330 mdata
->module_pa
= ddata
->module_pa
;
2331 mdata
->module_size
= ddata
->module_size
;
2332 mdata
->offsets
= ddata
->offsets
;
2333 mdata
->nr_offsets
= SYSC_MAX_REGS
;
2334 mdata
->cap
= ddata
->cap
;
2335 mdata
->cfg
= &ddata
->cfg
;
2338 ddata
->mdata
= mdata
;
2343 static int sysc_init_match(struct sysc
*ddata
)
2345 const struct sysc_capabilities
*cap
;
2347 cap
= of_device_get_match_data(ddata
->dev
);
2353 ddata
->cfg
.quirks
|= ddata
->cap
->mod_quirks
;
2358 static void ti_sysc_idle(struct work_struct
*work
)
2362 ddata
= container_of(work
, struct sysc
, idle_work
.work
);
2365 * One time decrement of clock usage counts if left on from init.
2366 * Note that we disable opt clocks unconditionally in this case
2367 * as they are enabled unconditionally during init without
2368 * considering sysc_opt_clks_needed() at that point.
2370 if (ddata
->cfg
.quirks
& (SYSC_QUIRK_NO_IDLE
|
2371 SYSC_QUIRK_NO_IDLE_ON_INIT
)) {
2372 sysc_disable_main_clocks(ddata
);
2373 sysc_disable_opt_clocks(ddata
);
2374 sysc_clkdm_allow_idle(ddata
);
2377 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
2378 if (ddata
->cfg
.quirks
& SYSC_QUIRK_NO_IDLE
)
2382 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
2383 * and SYSC_QUIRK_NO_RESET_ON_INIT
2385 if (pm_runtime_active(ddata
->dev
))
2386 pm_runtime_put_sync(ddata
->dev
);
2389 static const struct of_device_id sysc_match_table
[] = {
2390 { .compatible
= "simple-bus", },
2394 static int sysc_probe(struct platform_device
*pdev
)
2396 struct ti_sysc_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
2400 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
2404 ddata
->dev
= &pdev
->dev
;
2405 platform_set_drvdata(pdev
, ddata
);
2407 error
= sysc_init_match(ddata
);
2411 error
= sysc_init_dts_quirks(ddata
);
2415 error
= sysc_map_and_check_registers(ddata
);
2419 error
= sysc_init_sysc_mask(ddata
);
2423 error
= sysc_init_idlemodes(ddata
);
2427 error
= sysc_init_syss_mask(ddata
);
2431 error
= sysc_init_pdata(ddata
);
2435 sysc_init_early_quirks(ddata
);
2437 error
= sysc_get_clocks(ddata
);
2441 error
= sysc_init_resets(ddata
);
2445 error
= sysc_init_module(ddata
);
2449 pm_runtime_enable(ddata
->dev
);
2450 error
= pm_runtime_get_sync(ddata
->dev
);
2452 pm_runtime_put_noidle(ddata
->dev
);
2453 pm_runtime_disable(ddata
->dev
);
2457 /* Balance use counts as PM runtime should have enabled these all */
2458 if (!(ddata
->cfg
.quirks
& SYSC_QUIRK_NO_RESET_ON_INIT
))
2459 reset_control_assert(ddata
->rsts
);
2461 if (!(ddata
->cfg
.quirks
&
2462 (SYSC_QUIRK_NO_IDLE
| SYSC_QUIRK_NO_IDLE_ON_INIT
))) {
2463 sysc_disable_main_clocks(ddata
);
2464 sysc_disable_opt_clocks(ddata
);
2465 sysc_clkdm_allow_idle(ddata
);
2468 sysc_show_registers(ddata
);
2470 ddata
->dev
->type
= &sysc_device_type
;
2471 error
= of_platform_populate(ddata
->dev
->of_node
, sysc_match_table
,
2472 pdata
? pdata
->auxdata
: NULL
,
2477 INIT_DELAYED_WORK(&ddata
->idle_work
, ti_sysc_idle
);
2479 /* At least earlycon won't survive without deferred idle */
2480 if (ddata
->cfg
.quirks
& (SYSC_QUIRK_NO_IDLE
|
2481 SYSC_QUIRK_NO_IDLE_ON_INIT
|
2482 SYSC_QUIRK_NO_RESET_ON_INIT
)) {
2483 schedule_delayed_work(&ddata
->idle_work
, 3000);
2485 pm_runtime_put(&pdev
->dev
);
2491 pm_runtime_put_sync(&pdev
->dev
);
2492 pm_runtime_disable(&pdev
->dev
);
2494 sysc_unprepare(ddata
);
2499 static int sysc_remove(struct platform_device
*pdev
)
2501 struct sysc
*ddata
= platform_get_drvdata(pdev
);
2504 cancel_delayed_work_sync(&ddata
->idle_work
);
2506 error
= pm_runtime_get_sync(ddata
->dev
);
2508 pm_runtime_put_noidle(ddata
->dev
);
2509 pm_runtime_disable(ddata
->dev
);
2513 of_platform_depopulate(&pdev
->dev
);
2515 pm_runtime_put_sync(&pdev
->dev
);
2516 pm_runtime_disable(&pdev
->dev
);
2517 reset_control_assert(ddata
->rsts
);
2520 sysc_unprepare(ddata
);
2525 static const struct of_device_id sysc_match
[] = {
2526 { .compatible
= "ti,sysc-omap2", .data
= &sysc_omap2
, },
2527 { .compatible
= "ti,sysc-omap2-timer", .data
= &sysc_omap2_timer
, },
2528 { .compatible
= "ti,sysc-omap4", .data
= &sysc_omap4
, },
2529 { .compatible
= "ti,sysc-omap4-timer", .data
= &sysc_omap4_timer
, },
2530 { .compatible
= "ti,sysc-omap4-simple", .data
= &sysc_omap4_simple
, },
2531 { .compatible
= "ti,sysc-omap3430-sr", .data
= &sysc_34xx_sr
, },
2532 { .compatible
= "ti,sysc-omap3630-sr", .data
= &sysc_36xx_sr
, },
2533 { .compatible
= "ti,sysc-omap4-sr", .data
= &sysc_omap4_sr
, },
2534 { .compatible
= "ti,sysc-omap3-sham", .data
= &sysc_omap3_sham
, },
2535 { .compatible
= "ti,sysc-omap-aes", .data
= &sysc_omap3_aes
, },
2536 { .compatible
= "ti,sysc-mcasp", .data
= &sysc_omap4_mcasp
, },
2537 { .compatible
= "ti,sysc-dra7-mcasp", .data
= &sysc_dra7_mcasp
, },
2538 { .compatible
= "ti,sysc-usb-host-fs",
2539 .data
= &sysc_omap4_usb_host_fs
, },
2540 { .compatible
= "ti,sysc-dra7-mcan", .data
= &sysc_dra7_mcan
, },
2543 MODULE_DEVICE_TABLE(of
, sysc_match
);
2545 static struct platform_driver sysc_driver
= {
2546 .probe
= sysc_probe
,
2547 .remove
= sysc_remove
,
2550 .of_match_table
= sysc_match
,
2555 static int __init
sysc_init(void)
2557 bus_register_notifier(&platform_bus_type
, &sysc_nb
);
2559 return platform_driver_register(&sysc_driver
);
2561 module_init(sysc_init
);
2563 static void __exit
sysc_exit(void)
2565 bus_unregister_notifier(&platform_bus_type
, &sysc_nb
);
2566 platform_driver_unregister(&sysc_driver
);
2568 module_exit(sysc_exit
);
2570 MODULE_DESCRIPTION("TI sysc interconnect target driver");
2571 MODULE_LICENSE("GPL v2");