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 * @pre_reset_quirk: module specific pre-reset quirk
74 * @post_reset_quirk: module specific post-reset 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
78 * @module_unlock_quirk: module specific sysconfig unlock quirk
79 * @module_lock_quirk: module specific sysconfig lock quirk
85 void __iomem
*module_va
;
86 int offsets
[SYSC_MAX_REGS
];
87 struct ti_sysc_module_data
*mdata
;
89 const char **clock_roles
;
91 struct reset_control
*rsts
;
92 const char *legacy_mode
;
93 const struct sysc_capabilities
*cap
;
94 struct sysc_config cfg
;
95 struct ti_sysc_cookie cookie
;
98 unsigned int enabled
:1;
99 unsigned int needs_resume
:1;
100 unsigned int child_needs_resume
:1;
101 struct delayed_work idle_work
;
102 void (*pre_reset_quirk
)(struct sysc
*sysc
);
103 void (*post_reset_quirk
)(struct sysc
*sysc
);
104 void (*reset_done_quirk
)(struct sysc
*sysc
);
105 void (*module_enable_quirk
)(struct sysc
*sysc
);
106 void (*module_disable_quirk
)(struct sysc
*sysc
);
107 void (*module_unlock_quirk
)(struct sysc
*sysc
);
108 void (*module_lock_quirk
)(struct sysc
*sysc
);
111 static void sysc_parse_dts_quirks(struct sysc
*ddata
, struct device_node
*np
,
114 static void sysc_write(struct sysc
*ddata
, int offset
, u32 value
)
116 if (ddata
->cfg
.quirks
& SYSC_QUIRK_16BIT
) {
117 writew_relaxed(value
& 0xffff, ddata
->module_va
+ offset
);
119 /* Only i2c revision has LO and HI register with stride of 4 */
120 if (ddata
->offsets
[SYSC_REVISION
] >= 0 &&
121 offset
== ddata
->offsets
[SYSC_REVISION
]) {
122 u16 hi
= value
>> 16;
124 writew_relaxed(hi
, ddata
->module_va
+ offset
+ 4);
130 writel_relaxed(value
, ddata
->module_va
+ offset
);
133 static u32
sysc_read(struct sysc
*ddata
, int offset
)
135 if (ddata
->cfg
.quirks
& SYSC_QUIRK_16BIT
) {
138 val
= readw_relaxed(ddata
->module_va
+ offset
);
140 /* Only i2c revision has LO and HI register with stride of 4 */
141 if (ddata
->offsets
[SYSC_REVISION
] >= 0 &&
142 offset
== ddata
->offsets
[SYSC_REVISION
]) {
143 u16 tmp
= readw_relaxed(ddata
->module_va
+ offset
+ 4);
151 return readl_relaxed(ddata
->module_va
+ offset
);
154 static bool sysc_opt_clks_needed(struct sysc
*ddata
)
156 return !!(ddata
->cfg
.quirks
& SYSC_QUIRK_OPT_CLKS_NEEDED
);
159 static u32
sysc_read_revision(struct sysc
*ddata
)
161 int offset
= ddata
->offsets
[SYSC_REVISION
];
166 return sysc_read(ddata
, offset
);
169 static u32
sysc_read_sysconfig(struct sysc
*ddata
)
171 int offset
= ddata
->offsets
[SYSC_SYSCONFIG
];
176 return sysc_read(ddata
, offset
);
179 static u32
sysc_read_sysstatus(struct sysc
*ddata
)
181 int offset
= ddata
->offsets
[SYSC_SYSSTATUS
];
186 return sysc_read(ddata
, offset
);
189 /* Poll on reset status */
190 static int sysc_wait_softreset(struct sysc
*ddata
)
192 u32 sysc_mask
, syss_done
, rstval
;
193 int syss_offset
, error
= 0;
195 syss_offset
= ddata
->offsets
[SYSC_SYSSTATUS
];
196 sysc_mask
= BIT(ddata
->cap
->regbits
->srst_shift
);
198 if (ddata
->cfg
.quirks
& SYSS_QUIRK_RESETDONE_INVERTED
)
201 syss_done
= ddata
->cfg
.syss_mask
;
203 if (syss_offset
>= 0) {
204 error
= readx_poll_timeout_atomic(sysc_read_sysstatus
, ddata
,
205 rstval
, (rstval
& ddata
->cfg
.syss_mask
) ==
206 syss_done
, 100, MAX_MODULE_SOFTRESET_WAIT
);
208 } else if (ddata
->cfg
.quirks
& SYSC_QUIRK_RESET_STATUS
) {
209 error
= readx_poll_timeout_atomic(sysc_read_sysconfig
, ddata
,
210 rstval
, !(rstval
& sysc_mask
),
211 100, MAX_MODULE_SOFTRESET_WAIT
);
217 static int sysc_add_named_clock_from_child(struct sysc
*ddata
,
219 const char *optfck_name
)
221 struct device_node
*np
= ddata
->dev
->of_node
;
222 struct device_node
*child
;
223 struct clk_lookup
*cl
;
232 /* Does the clock alias already exist? */
233 clock
= of_clk_get_by_name(np
, n
);
234 if (!IS_ERR(clock
)) {
240 child
= of_get_next_available_child(np
, NULL
);
244 clock
= devm_get_clk_from_child(ddata
->dev
, child
, name
);
246 return PTR_ERR(clock
);
249 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
250 * limit for clk_get(). If cl ever needs to be freed, it should be done
251 * with clkdev_drop().
253 cl
= kcalloc(1, sizeof(*cl
), GFP_KERNEL
);
258 cl
->dev_id
= dev_name(ddata
->dev
);
267 static int sysc_init_ext_opt_clock(struct sysc
*ddata
, const char *name
)
269 const char *optfck_name
;
272 if (ddata
->nr_clocks
< SYSC_OPTFCK0
)
273 index
= SYSC_OPTFCK0
;
275 index
= ddata
->nr_clocks
;
280 optfck_name
= clock_names
[index
];
282 error
= sysc_add_named_clock_from_child(ddata
, name
, optfck_name
);
286 ddata
->clock_roles
[index
] = optfck_name
;
292 static int sysc_get_one_clock(struct sysc
*ddata
, const char *name
)
294 int error
, i
, index
= -ENODEV
;
296 if (!strncmp(clock_names
[SYSC_FCK
], name
, 3))
298 else if (!strncmp(clock_names
[SYSC_ICK
], name
, 3))
302 for (i
= SYSC_OPTFCK0
; i
< SYSC_MAX_CLOCKS
; i
++) {
303 if (!ddata
->clocks
[i
]) {
311 dev_err(ddata
->dev
, "clock %s not added\n", name
);
315 ddata
->clocks
[index
] = devm_clk_get(ddata
->dev
, name
);
316 if (IS_ERR(ddata
->clocks
[index
])) {
317 dev_err(ddata
->dev
, "clock get error for %s: %li\n",
318 name
, PTR_ERR(ddata
->clocks
[index
]));
320 return PTR_ERR(ddata
->clocks
[index
]);
323 error
= clk_prepare(ddata
->clocks
[index
]);
325 dev_err(ddata
->dev
, "clock prepare error for %s: %i\n",
334 static int sysc_get_clocks(struct sysc
*ddata
)
336 struct device_node
*np
= ddata
->dev
->of_node
;
337 struct property
*prop
;
339 int nr_fck
= 0, nr_ick
= 0, i
, error
= 0;
341 ddata
->clock_roles
= devm_kcalloc(ddata
->dev
,
343 sizeof(*ddata
->clock_roles
),
345 if (!ddata
->clock_roles
)
348 of_property_for_each_string(np
, "clock-names", prop
, name
) {
349 if (!strncmp(clock_names
[SYSC_FCK
], name
, 3))
351 if (!strncmp(clock_names
[SYSC_ICK
], name
, 3))
353 ddata
->clock_roles
[ddata
->nr_clocks
] = name
;
357 if (ddata
->nr_clocks
< 1)
360 if ((ddata
->cfg
.quirks
& SYSC_QUIRK_EXT_OPT_CLOCK
)) {
361 error
= sysc_init_ext_opt_clock(ddata
, NULL
);
366 if (ddata
->nr_clocks
> SYSC_MAX_CLOCKS
) {
367 dev_err(ddata
->dev
, "too many clocks for %pOF\n", np
);
372 if (nr_fck
> 1 || nr_ick
> 1) {
373 dev_err(ddata
->dev
, "max one fck and ick for %pOF\n", np
);
378 /* Always add a slot for main clocks fck and ick even if unused */
384 ddata
->clocks
= devm_kcalloc(ddata
->dev
,
385 ddata
->nr_clocks
, sizeof(*ddata
->clocks
),
390 for (i
= 0; i
< SYSC_MAX_CLOCKS
; i
++) {
391 const char *name
= ddata
->clock_roles
[i
];
396 error
= sysc_get_one_clock(ddata
, name
);
404 static int sysc_enable_main_clocks(struct sysc
*ddata
)
412 for (i
= 0; i
< SYSC_OPTFCK0
; i
++) {
413 clock
= ddata
->clocks
[i
];
415 /* Main clocks may not have ick */
416 if (IS_ERR_OR_NULL(clock
))
419 error
= clk_enable(clock
);
427 for (i
--; i
>= 0; i
--) {
428 clock
= ddata
->clocks
[i
];
430 /* Main clocks may not have ick */
431 if (IS_ERR_OR_NULL(clock
))
440 static void sysc_disable_main_clocks(struct sysc
*ddata
)
448 for (i
= 0; i
< SYSC_OPTFCK0
; i
++) {
449 clock
= ddata
->clocks
[i
];
450 if (IS_ERR_OR_NULL(clock
))
457 static int sysc_enable_opt_clocks(struct sysc
*ddata
)
462 if (!ddata
->clocks
|| ddata
->nr_clocks
< SYSC_OPTFCK0
+ 1)
465 for (i
= SYSC_OPTFCK0
; i
< SYSC_MAX_CLOCKS
; i
++) {
466 clock
= ddata
->clocks
[i
];
468 /* Assume no holes for opt clocks */
469 if (IS_ERR_OR_NULL(clock
))
472 error
= clk_enable(clock
);
480 for (i
--; i
>= 0; i
--) {
481 clock
= ddata
->clocks
[i
];
482 if (IS_ERR_OR_NULL(clock
))
491 static void sysc_disable_opt_clocks(struct sysc
*ddata
)
496 if (!ddata
->clocks
|| ddata
->nr_clocks
< SYSC_OPTFCK0
+ 1)
499 for (i
= SYSC_OPTFCK0
; i
< SYSC_MAX_CLOCKS
; i
++) {
500 clock
= ddata
->clocks
[i
];
502 /* Assume no holes for opt clocks */
503 if (IS_ERR_OR_NULL(clock
))
510 static void sysc_clkdm_deny_idle(struct sysc
*ddata
)
512 struct ti_sysc_platform_data
*pdata
;
514 if (ddata
->legacy_mode
|| (ddata
->cfg
.quirks
& SYSC_QUIRK_CLKDM_NOAUTO
))
517 pdata
= dev_get_platdata(ddata
->dev
);
518 if (pdata
&& pdata
->clkdm_deny_idle
)
519 pdata
->clkdm_deny_idle(ddata
->dev
, &ddata
->cookie
);
522 static void sysc_clkdm_allow_idle(struct sysc
*ddata
)
524 struct ti_sysc_platform_data
*pdata
;
526 if (ddata
->legacy_mode
|| (ddata
->cfg
.quirks
& SYSC_QUIRK_CLKDM_NOAUTO
))
529 pdata
= dev_get_platdata(ddata
->dev
);
530 if (pdata
&& pdata
->clkdm_allow_idle
)
531 pdata
->clkdm_allow_idle(ddata
->dev
, &ddata
->cookie
);
535 * sysc_init_resets - init rstctrl reset line if configured
536 * @ddata: device driver data
538 * See sysc_rstctrl_reset_deassert().
540 static int sysc_init_resets(struct sysc
*ddata
)
543 devm_reset_control_get_optional_shared(ddata
->dev
, "rstctrl");
544 if (IS_ERR(ddata
->rsts
))
545 return PTR_ERR(ddata
->rsts
);
551 * sysc_parse_and_check_child_range - parses module IO region from ranges
552 * @ddata: device driver data
554 * In general we only need rev, syss, and sysc registers and not the whole
555 * module range. But we do want the offsets for these registers from the
556 * module base. This allows us to check them against the legacy hwmod
557 * platform data. Let's also check the ranges are configured properly.
559 static int sysc_parse_and_check_child_range(struct sysc
*ddata
)
561 struct device_node
*np
= ddata
->dev
->of_node
;
562 const __be32
*ranges
;
563 u32 nr_addr
, nr_size
;
566 ranges
= of_get_property(np
, "ranges", &len
);
568 dev_err(ddata
->dev
, "missing ranges for %pOF\n", np
);
573 len
/= sizeof(*ranges
);
576 dev_err(ddata
->dev
, "incomplete ranges for %pOF\n", np
);
581 error
= of_property_read_u32(np
, "#address-cells", &nr_addr
);
585 error
= of_property_read_u32(np
, "#size-cells", &nr_size
);
589 if (nr_addr
!= 1 || nr_size
!= 1) {
590 dev_err(ddata
->dev
, "invalid ranges for %pOF\n", np
);
596 ddata
->module_pa
= of_translate_address(np
, ranges
++);
597 ddata
->module_size
= be32_to_cpup(ranges
);
602 static struct device_node
*stdout_path
;
604 static void sysc_init_stdout_path(struct sysc
*ddata
)
606 struct device_node
*np
= NULL
;
609 if (IS_ERR(stdout_path
))
615 np
= of_find_node_by_path("/chosen");
619 uart
= of_get_property(np
, "stdout-path", NULL
);
623 np
= of_find_node_by_path(uart
);
632 stdout_path
= ERR_PTR(-ENODEV
);
635 static void sysc_check_quirk_stdout(struct sysc
*ddata
,
636 struct device_node
*np
)
638 sysc_init_stdout_path(ddata
);
639 if (np
!= stdout_path
)
642 ddata
->cfg
.quirks
|= SYSC_QUIRK_NO_IDLE_ON_INIT
|
643 SYSC_QUIRK_NO_RESET_ON_INIT
;
647 * sysc_check_one_child - check child configuration
648 * @ddata: device driver data
649 * @np: child device node
651 * Let's avoid messy situations where we have new interconnect target
652 * node but children have "ti,hwmods". These belong to the interconnect
653 * target node and are managed by this driver.
655 static void sysc_check_one_child(struct sysc
*ddata
,
656 struct device_node
*np
)
660 name
= of_get_property(np
, "ti,hwmods", NULL
);
662 dev_warn(ddata
->dev
, "really a child ti,hwmods property?");
664 sysc_check_quirk_stdout(ddata
, np
);
665 sysc_parse_dts_quirks(ddata
, np
, true);
668 static void sysc_check_children(struct sysc
*ddata
)
670 struct device_node
*child
;
672 for_each_child_of_node(ddata
->dev
->of_node
, child
)
673 sysc_check_one_child(ddata
, child
);
677 * So far only I2C uses 16-bit read access with clockactivity with revision
678 * in two registers with stride of 4. We can detect this based on the rev
679 * register size to configure things far enough to be able to properly read
680 * the revision register.
682 static void sysc_check_quirk_16bit(struct sysc
*ddata
, struct resource
*res
)
684 if (resource_size(res
) == 8)
685 ddata
->cfg
.quirks
|= SYSC_QUIRK_16BIT
| SYSC_QUIRK_USE_CLOCKACT
;
689 * sysc_parse_one - parses the interconnect target module registers
690 * @ddata: device driver data
691 * @reg: register to parse
693 static int sysc_parse_one(struct sysc
*ddata
, enum sysc_registers reg
)
695 struct resource
*res
;
702 name
= reg_names
[reg
];
708 res
= platform_get_resource_byname(to_platform_device(ddata
->dev
),
709 IORESOURCE_MEM
, name
);
711 ddata
->offsets
[reg
] = -ENODEV
;
716 ddata
->offsets
[reg
] = res
->start
- ddata
->module_pa
;
717 if (reg
== SYSC_REVISION
)
718 sysc_check_quirk_16bit(ddata
, res
);
723 static int sysc_parse_registers(struct sysc
*ddata
)
727 for (i
= 0; i
< SYSC_MAX_REGS
; i
++) {
728 error
= sysc_parse_one(ddata
, i
);
737 * sysc_check_registers - check for misconfigured register overlaps
738 * @ddata: device driver data
740 static int sysc_check_registers(struct sysc
*ddata
)
742 int i
, j
, nr_regs
= 0, nr_matches
= 0;
744 for (i
= 0; i
< SYSC_MAX_REGS
; i
++) {
745 if (ddata
->offsets
[i
] < 0)
748 if (ddata
->offsets
[i
] > (ddata
->module_size
- 4)) {
749 dev_err(ddata
->dev
, "register outside module range");
754 for (j
= 0; j
< SYSC_MAX_REGS
; j
++) {
755 if (ddata
->offsets
[j
] < 0)
758 if (ddata
->offsets
[i
] == ddata
->offsets
[j
])
764 if (nr_matches
> nr_regs
) {
765 dev_err(ddata
->dev
, "overlapping registers: (%i/%i)",
766 nr_regs
, nr_matches
);
775 * syc_ioremap - ioremap register space for the interconnect target module
776 * @ddata: device driver data
778 * Note that the interconnect target module registers can be anywhere
779 * within the interconnect target module range. For example, SGX has
780 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
781 * has them at offset 0x1200 in the CPSW_WR child. Usually the
782 * the interconnect target module registers are at the beginning of
783 * the module range though.
785 static int sysc_ioremap(struct sysc
*ddata
)
789 if (ddata
->offsets
[SYSC_REVISION
] < 0 &&
790 ddata
->offsets
[SYSC_SYSCONFIG
] < 0 &&
791 ddata
->offsets
[SYSC_SYSSTATUS
] < 0) {
792 size
= ddata
->module_size
;
794 size
= max3(ddata
->offsets
[SYSC_REVISION
],
795 ddata
->offsets
[SYSC_SYSCONFIG
],
796 ddata
->offsets
[SYSC_SYSSTATUS
]);
801 if ((size
+ sizeof(u32
)) > ddata
->module_size
)
802 size
= ddata
->module_size
;
805 ddata
->module_va
= devm_ioremap(ddata
->dev
,
808 if (!ddata
->module_va
)
815 * sysc_map_and_check_registers - ioremap and check device registers
816 * @ddata: device driver data
818 static int sysc_map_and_check_registers(struct sysc
*ddata
)
822 error
= sysc_parse_and_check_child_range(ddata
);
826 sysc_check_children(ddata
);
828 error
= sysc_parse_registers(ddata
);
832 error
= sysc_ioremap(ddata
);
836 error
= sysc_check_registers(ddata
);
844 * sysc_show_rev - read and show interconnect target module revision
845 * @bufp: buffer to print the information to
846 * @ddata: device driver data
848 static int sysc_show_rev(char *bufp
, struct sysc
*ddata
)
852 if (ddata
->offsets
[SYSC_REVISION
] < 0)
853 return sprintf(bufp
, ":NA");
855 len
= sprintf(bufp
, ":%08x", ddata
->revision
);
860 static int sysc_show_reg(struct sysc
*ddata
,
861 char *bufp
, enum sysc_registers reg
)
863 if (ddata
->offsets
[reg
] < 0)
864 return sprintf(bufp
, ":NA");
866 return sprintf(bufp
, ":%x", ddata
->offsets
[reg
]);
869 static int sysc_show_name(char *bufp
, struct sysc
*ddata
)
874 return sprintf(bufp
, ":%s", ddata
->name
);
878 * sysc_show_registers - show information about interconnect target module
879 * @ddata: device driver data
881 static void sysc_show_registers(struct sysc
*ddata
)
887 for (i
= 0; i
< SYSC_MAX_REGS
; i
++)
888 bufp
+= sysc_show_reg(ddata
, bufp
, i
);
890 bufp
+= sysc_show_rev(bufp
, ddata
);
891 bufp
+= sysc_show_name(bufp
, ddata
);
893 dev_dbg(ddata
->dev
, "%llx:%x%s\n",
894 ddata
->module_pa
, ddata
->module_size
,
899 * sysc_write_sysconfig - handle sysconfig quirks for register write
900 * @ddata: device driver data
901 * @value: register value
903 static void sysc_write_sysconfig(struct sysc
*ddata
, u32 value
)
905 if (ddata
->module_unlock_quirk
)
906 ddata
->module_unlock_quirk(ddata
);
908 sysc_write(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
], value
);
910 if (ddata
->module_lock_quirk
)
911 ddata
->module_lock_quirk(ddata
);
914 #define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
915 #define SYSC_CLOCACT_ICK 2
917 /* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
918 static int sysc_enable_module(struct device
*dev
)
921 const struct sysc_regbits
*regbits
;
922 u32 reg
, idlemodes
, best_mode
;
925 ddata
= dev_get_drvdata(dev
);
928 * Some modules like DSS reset automatically on idle. Enable optional
929 * reset clocks and wait for OCP softreset to complete.
931 if (ddata
->cfg
.quirks
& SYSC_QUIRK_OPT_CLKS_IN_RESET
) {
932 error
= sysc_enable_opt_clocks(ddata
);
935 "Optional clocks failed for enable: %i\n",
940 error
= sysc_wait_softreset(ddata
);
942 dev_warn(ddata
->dev
, "OCP softreset timed out\n");
943 if (ddata
->cfg
.quirks
& SYSC_QUIRK_OPT_CLKS_IN_RESET
)
944 sysc_disable_opt_clocks(ddata
);
947 * Some subsystem private interconnects, like DSS top level module,
948 * need only the automatic OCP softreset handling with no sysconfig
949 * register bits to configure.
951 if (ddata
->offsets
[SYSC_SYSCONFIG
] == -ENODEV
)
954 regbits
= ddata
->cap
->regbits
;
955 reg
= sysc_read(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
]);
958 * Set CLOCKACTIVITY, we only use it for ick. And we only configure it
959 * based on the SYSC_QUIRK_USE_CLOCKACT flag, not based on the hardware
960 * capabilities. See the old HWMOD_SET_DEFAULT_CLOCKACT flag.
962 if (regbits
->clkact_shift
>= 0 &&
963 (ddata
->cfg
.quirks
& SYSC_QUIRK_USE_CLOCKACT
))
964 reg
|= SYSC_CLOCACT_ICK
<< regbits
->clkact_shift
;
967 idlemodes
= ddata
->cfg
.sidlemodes
;
968 if (!idlemodes
|| regbits
->sidle_shift
< 0)
971 if (ddata
->cfg
.quirks
& (SYSC_QUIRK_SWSUP_SIDLE
|
972 SYSC_QUIRK_SWSUP_SIDLE_ACT
)) {
973 best_mode
= SYSC_IDLE_NO
;
975 best_mode
= fls(ddata
->cfg
.sidlemodes
) - 1;
976 if (best_mode
> SYSC_IDLE_MASK
) {
977 dev_err(dev
, "%s: invalid sidlemode\n", __func__
);
982 if (regbits
->enwkup_shift
>= 0 &&
983 ddata
->cfg
.sysc_val
& BIT(regbits
->enwkup_shift
))
984 reg
|= BIT(regbits
->enwkup_shift
);
987 reg
&= ~(SYSC_IDLE_MASK
<< regbits
->sidle_shift
);
988 reg
|= best_mode
<< regbits
->sidle_shift
;
989 sysc_write_sysconfig(ddata
, reg
);
993 idlemodes
= ddata
->cfg
.midlemodes
;
994 if (!idlemodes
|| regbits
->midle_shift
< 0)
997 best_mode
= fls(ddata
->cfg
.midlemodes
) - 1;
998 if (best_mode
> SYSC_IDLE_MASK
) {
999 dev_err(dev
, "%s: invalid midlemode\n", __func__
);
1003 if (ddata
->cfg
.quirks
& SYSC_QUIRK_SWSUP_MSTANDBY
)
1004 best_mode
= SYSC_IDLE_NO
;
1006 reg
&= ~(SYSC_IDLE_MASK
<< regbits
->midle_shift
);
1007 reg
|= best_mode
<< regbits
->midle_shift
;
1008 sysc_write_sysconfig(ddata
, reg
);
1011 /* Autoidle bit must enabled separately if available */
1012 if (regbits
->autoidle_shift
>= 0 &&
1013 ddata
->cfg
.sysc_val
& BIT(regbits
->autoidle_shift
)) {
1014 reg
|= 1 << regbits
->autoidle_shift
;
1015 sysc_write_sysconfig(ddata
, reg
);
1018 /* Flush posted write */
1019 sysc_read(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
]);
1021 if (ddata
->module_enable_quirk
)
1022 ddata
->module_enable_quirk(ddata
);
1027 static int sysc_best_idle_mode(u32 idlemodes
, u32
*best_mode
)
1029 if (idlemodes
& BIT(SYSC_IDLE_SMART_WKUP
))
1030 *best_mode
= SYSC_IDLE_SMART_WKUP
;
1031 else if (idlemodes
& BIT(SYSC_IDLE_SMART
))
1032 *best_mode
= SYSC_IDLE_SMART
;
1033 else if (idlemodes
& BIT(SYSC_IDLE_FORCE
))
1034 *best_mode
= SYSC_IDLE_FORCE
;
1041 /* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
1042 static int sysc_disable_module(struct device
*dev
)
1045 const struct sysc_regbits
*regbits
;
1046 u32 reg
, idlemodes
, best_mode
;
1049 ddata
= dev_get_drvdata(dev
);
1050 if (ddata
->offsets
[SYSC_SYSCONFIG
] == -ENODEV
)
1053 if (ddata
->module_disable_quirk
)
1054 ddata
->module_disable_quirk(ddata
);
1056 regbits
= ddata
->cap
->regbits
;
1057 reg
= sysc_read(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
]);
1059 /* Set MIDLE mode */
1060 idlemodes
= ddata
->cfg
.midlemodes
;
1061 if (!idlemodes
|| regbits
->midle_shift
< 0)
1064 ret
= sysc_best_idle_mode(idlemodes
, &best_mode
);
1066 dev_err(dev
, "%s: invalid midlemode\n", __func__
);
1070 if (ddata
->cfg
.quirks
& (SYSC_QUIRK_SWSUP_MSTANDBY
) ||
1071 ddata
->cfg
.quirks
& (SYSC_QUIRK_FORCE_MSTANDBY
))
1072 best_mode
= SYSC_IDLE_FORCE
;
1074 reg
&= ~(SYSC_IDLE_MASK
<< regbits
->midle_shift
);
1075 reg
|= best_mode
<< regbits
->midle_shift
;
1076 sysc_write_sysconfig(ddata
, reg
);
1079 /* Set SIDLE mode */
1080 idlemodes
= ddata
->cfg
.sidlemodes
;
1081 if (!idlemodes
|| regbits
->sidle_shift
< 0)
1084 if (ddata
->cfg
.quirks
& SYSC_QUIRK_SWSUP_SIDLE
) {
1085 best_mode
= SYSC_IDLE_FORCE
;
1087 ret
= sysc_best_idle_mode(idlemodes
, &best_mode
);
1089 dev_err(dev
, "%s: invalid sidlemode\n", __func__
);
1094 reg
&= ~(SYSC_IDLE_MASK
<< regbits
->sidle_shift
);
1095 reg
|= best_mode
<< regbits
->sidle_shift
;
1096 if (regbits
->autoidle_shift
>= 0 &&
1097 ddata
->cfg
.sysc_val
& BIT(regbits
->autoidle_shift
))
1098 reg
|= 1 << regbits
->autoidle_shift
;
1099 sysc_write_sysconfig(ddata
, reg
);
1101 /* Flush posted write */
1102 sysc_read(ddata
, ddata
->offsets
[SYSC_SYSCONFIG
]);
1107 static int __maybe_unused
sysc_runtime_suspend_legacy(struct device
*dev
,
1110 struct ti_sysc_platform_data
*pdata
;
1113 pdata
= dev_get_platdata(ddata
->dev
);
1117 if (!pdata
->idle_module
)
1120 error
= pdata
->idle_module(dev
, &ddata
->cookie
);
1122 dev_err(dev
, "%s: could not idle: %i\n",
1125 reset_control_assert(ddata
->rsts
);
1130 static int __maybe_unused
sysc_runtime_resume_legacy(struct device
*dev
,
1133 struct ti_sysc_platform_data
*pdata
;
1136 reset_control_deassert(ddata
->rsts
);
1138 pdata
= dev_get_platdata(ddata
->dev
);
1142 if (!pdata
->enable_module
)
1145 error
= pdata
->enable_module(dev
, &ddata
->cookie
);
1147 dev_err(dev
, "%s: could not enable: %i\n",
1153 static int __maybe_unused
sysc_runtime_suspend(struct device
*dev
)
1158 ddata
= dev_get_drvdata(dev
);
1160 if (!ddata
->enabled
)
1163 sysc_clkdm_deny_idle(ddata
);
1165 if (ddata
->legacy_mode
) {
1166 error
= sysc_runtime_suspend_legacy(dev
, ddata
);
1168 goto err_allow_idle
;
1170 error
= sysc_disable_module(dev
);
1172 goto err_allow_idle
;
1175 sysc_disable_main_clocks(ddata
);
1177 if (sysc_opt_clks_needed(ddata
))
1178 sysc_disable_opt_clocks(ddata
);
1180 ddata
->enabled
= false;
1183 reset_control_assert(ddata
->rsts
);
1185 sysc_clkdm_allow_idle(ddata
);
1190 static int __maybe_unused
sysc_runtime_resume(struct device
*dev
)
1195 ddata
= dev_get_drvdata(dev
);
1201 sysc_clkdm_deny_idle(ddata
);
1203 reset_control_deassert(ddata
->rsts
);
1205 if (sysc_opt_clks_needed(ddata
)) {
1206 error
= sysc_enable_opt_clocks(ddata
);
1208 goto err_allow_idle
;
1211 error
= sysc_enable_main_clocks(ddata
);
1213 goto err_opt_clocks
;
1215 if (ddata
->legacy_mode
) {
1216 error
= sysc_runtime_resume_legacy(dev
, ddata
);
1218 goto err_main_clocks
;
1220 error
= sysc_enable_module(dev
);
1222 goto err_main_clocks
;
1225 ddata
->enabled
= true;
1227 sysc_clkdm_allow_idle(ddata
);
1232 sysc_disable_main_clocks(ddata
);
1234 if (sysc_opt_clks_needed(ddata
))
1235 sysc_disable_opt_clocks(ddata
);
1237 sysc_clkdm_allow_idle(ddata
);
1242 static int __maybe_unused
sysc_noirq_suspend(struct device
*dev
)
1246 ddata
= dev_get_drvdata(dev
);
1248 if (ddata
->cfg
.quirks
&
1249 (SYSC_QUIRK_LEGACY_IDLE
| SYSC_QUIRK_NO_IDLE
))
1252 return pm_runtime_force_suspend(dev
);
1255 static int __maybe_unused
sysc_noirq_resume(struct device
*dev
)
1259 ddata
= dev_get_drvdata(dev
);
1261 if (ddata
->cfg
.quirks
&
1262 (SYSC_QUIRK_LEGACY_IDLE
| SYSC_QUIRK_NO_IDLE
))
1265 return pm_runtime_force_resume(dev
);
1268 static const struct dev_pm_ops sysc_pm_ops
= {
1269 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend
, sysc_noirq_resume
)
1270 SET_RUNTIME_PM_OPS(sysc_runtime_suspend
,
1271 sysc_runtime_resume
,
1275 /* Module revision register based quirks */
1276 struct sysc_revision_quirk
{
1287 #define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1288 optrev_val, optrevmask, optquirkmask) \
1290 .name = (optname), \
1291 .base = (optbase), \
1292 .rev_offset = (optrev), \
1293 .sysc_offset = (optsysc), \
1294 .syss_offset = (optsyss), \
1295 .revision = (optrev_val), \
1296 .revision_mask = (optrevmask), \
1297 .quirks = (optquirkmask), \
1300 static const struct sysc_revision_quirk sysc_revision_quirks
[] = {
1301 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
1302 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
1303 SYSC_QUIRK_LEGACY_IDLE
| SYSC_QUIRK_OPT_CLKS_IN_RESET
),
1304 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
1305 SYSC_QUIRK_LEGACY_IDLE
),
1306 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff,
1307 SYSC_QUIRK_LEGACY_IDLE
),
1308 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1309 SYSC_QUIRK_LEGACY_IDLE
),
1310 SYSC_QUIRK("smartreflex", 0, -ENODEV
, 0x24, -ENODEV
, 0x00000000, 0xffffffff,
1311 SYSC_QUIRK_LEGACY_IDLE
),
1312 SYSC_QUIRK("smartreflex", 0, -ENODEV
, 0x38, -ENODEV
, 0x00000000, 0xffffffff,
1313 SYSC_QUIRK_LEGACY_IDLE
),
1314 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff,
1316 /* Some timers on omap4 and later */
1317 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV
, 0x50002100, 0xffffffff,
1319 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV
, 0x4fff1301, 0xffff00ff,
1321 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1322 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_LEGACY_IDLE
),
1323 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
1324 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_LEGACY_IDLE
),
1325 /* Uarts on omap4 and later */
1326 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
1327 SYSC_QUIRK_SWSUP_SIDLE_ACT
| SYSC_QUIRK_LEGACY_IDLE
),
1328 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
1329 SYSC_QUIRK_SWSUP_SIDLE_ACT
| SYSC_QUIRK_LEGACY_IDLE
),
1331 /* Quirks that need to be set based on the module address */
1332 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -ENODEV
, 0x50000800, 0xffffffff,
1333 SYSC_QUIRK_EXT_OPT_CLOCK
| SYSC_QUIRK_NO_RESET_ON_INIT
|
1334 SYSC_QUIRK_SWSUP_SIDLE
),
1336 /* Quirks that need to be set based on detected module */
1337 SYSC_QUIRK("aess", 0, 0, 0x10, -ENODEV
, 0x40000000, 0xffffffff,
1338 SYSC_MODULE_QUIRK_AESS
),
1339 SYSC_QUIRK("dcan", 0x48480000, 0x20, -ENODEV
, -ENODEV
, 0xa3170504, 0xffffffff,
1340 SYSC_QUIRK_CLKDM_NOAUTO
),
1341 SYSC_QUIRK("dss", 0x4832a000, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
1342 SYSC_QUIRK_OPT_CLKS_IN_RESET
),
1343 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV
, 0x14, 0x00000040, 0xffffffff,
1344 SYSC_QUIRK_OPT_CLKS_IN_RESET
),
1345 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV
, 0x14, 0x00000061, 0xffffffff,
1346 SYSC_QUIRK_OPT_CLKS_IN_RESET
),
1347 SYSC_QUIRK("dwc3", 0x48880000, 0, 0x10, -ENODEV
, 0x500a0200, 0xffffffff,
1348 SYSC_QUIRK_CLKDM_NOAUTO
),
1349 SYSC_QUIRK("dwc3", 0x488c0000, 0, 0x10, -ENODEV
, 0x500a0200, 0xffffffff,
1350 SYSC_QUIRK_CLKDM_NOAUTO
),
1351 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV
, 0x50030200, 0xffffffff,
1352 SYSC_QUIRK_OPT_CLKS_NEEDED
),
1353 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
1354 SYSC_MODULE_QUIRK_HDQ1W
),
1355 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
1356 SYSC_MODULE_QUIRK_HDQ1W
),
1357 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
1358 SYSC_MODULE_QUIRK_I2C
),
1359 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
1360 SYSC_MODULE_QUIRK_I2C
),
1361 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
1362 SYSC_MODULE_QUIRK_I2C
),
1363 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
1364 SYSC_MODULE_QUIRK_I2C
),
1365 SYSC_QUIRK("gpu", 0x50000000, 0x14, -ENODEV
, -ENODEV
, 0x00010201, 0xffffffff, 0),
1366 SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -ENODEV
, 0x40000000 , 0xffffffff,
1367 SYSC_MODULE_QUIRK_SGX
),
1368 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -ENODEV
, 0x4eb01908, 0xffff00f0,
1369 SYSC_MODULE_QUIRK_RTC_UNLOCK
),
1370 SYSC_QUIRK("tptc", 0, 0, 0x10, -ENODEV
, 0x40006c00, 0xffffefff,
1371 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_SWSUP_MSTANDBY
),
1372 SYSC_QUIRK("tptc", 0, 0, -ENODEV
, -ENODEV
, 0x40007c00, 0xffffffff,
1373 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_SWSUP_MSTANDBY
),
1374 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff,
1375 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_SWSUP_MSTANDBY
),
1376 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -ENODEV
, 0x50700101, 0xffffffff,
1377 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_SWSUP_MSTANDBY
),
1378 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1379 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_SWSUP_MSTANDBY
),
1380 SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -ENODEV
, 0x4ea2080d, 0xffffffff,
1381 SYSC_QUIRK_SWSUP_SIDLE
| SYSC_QUIRK_SWSUP_MSTANDBY
),
1382 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1383 SYSC_MODULE_QUIRK_WDT
),
1384 /* Watchdog on am3 and am4 */
1385 SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1386 SYSC_MODULE_QUIRK_WDT
| SYSC_QUIRK_SWSUP_SIDLE
),
1389 SYSC_QUIRK("adc", 0, 0, 0x10, -ENODEV
, 0x47300001, 0xffffffff, 0),
1390 SYSC_QUIRK("atl", 0, 0, -ENODEV
, -ENODEV
, 0x0a070100, 0xffffffff, 0),
1391 SYSC_QUIRK("cm", 0, 0, -ENODEV
, -ENODEV
, 0x40000301, 0xffffffff, 0),
1392 SYSC_QUIRK("control", 0, 0, 0x10, -ENODEV
, 0x40000900, 0xffffffff, 0),
1393 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
1395 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV
, -ENODEV
, 0xa3170504, 0xffffffff, 0),
1396 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV
, -ENODEV
, 0x4edb1902, 0xffffffff, 0),
1397 SYSC_QUIRK("dispc", 0x4832a400, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1398 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1399 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000051, 0xffffffff, 0),
1400 SYSC_QUIRK("dmic", 0, 0, 0x10, -ENODEV
, 0x50010000, 0xffffffff, 0),
1401 SYSC_QUIRK("dsi", 0x58004000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1402 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1403 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1404 SYSC_QUIRK("dsi", 0x58009000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1405 SYSC_QUIRK("dwc3", 0, 0, 0x10, -ENODEV
, 0x500a0200, 0xffffffff, 0),
1406 SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1407 SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1408 SYSC_QUIRK("epwmss", 0, 0, 0x4, -ENODEV
, 0x47400001, 0xffffffff, 0),
1409 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -ENODEV
, 0, 0, 0),
1410 SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -ENODEV
, 0x40000000 , 0xffffffff, 0),
1411 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV
, 0x50031d00, 0xffffffff, 0),
1412 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
1413 SYSC_QUIRK("iss", 0, 0, 0x10, -ENODEV
, 0x40000101, 0xffffffff, 0),
1414 SYSC_QUIRK("lcdc", 0, 0, 0x54, -ENODEV
, 0x4f201000, 0xffffffff, 0),
1415 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV
, 0x44306302, 0xffffffff, 0),
1416 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV
, 0x44307b02, 0xffffffff, 0),
1417 SYSC_QUIRK("mcbsp", 0, -ENODEV
, 0x8c, -ENODEV
, 0, 0, 0),
1418 SYSC_QUIRK("mcspi", 0, 0, 0x10, -ENODEV
, 0x40300a0b, 0xffff00ff, 0),
1419 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
1420 SYSC_QUIRK("mailbox", 0, 0, 0x10, -ENODEV
, 0x00000400, 0xffffffff, 0),
1421 SYSC_QUIRK("m3", 0, 0, -ENODEV
, -ENODEV
, 0x5f580105, 0x0fff0f00, 0),
1422 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
1423 SYSC_QUIRK("ocp2scp", 0, 0, -ENODEV
, -ENODEV
, 0x50060007, 0xffffffff, 0),
1424 SYSC_QUIRK("padconf", 0, 0, 0x10, -ENODEV
, 0x4fff0800, 0xffffffff, 0),
1425 SYSC_QUIRK("padconf", 0, 0, -ENODEV
, -ENODEV
, 0x40001100, 0xffffffff, 0),
1426 SYSC_QUIRK("prcm", 0, 0, -ENODEV
, -ENODEV
, 0x40000100, 0xffffffff, 0),
1427 SYSC_QUIRK("prcm", 0, 0, -ENODEV
, -ENODEV
, 0x00004102, 0xffffffff, 0),
1428 SYSC_QUIRK("prcm", 0, 0, -ENODEV
, -ENODEV
, 0x40000400, 0xffffffff, 0),
1429 SYSC_QUIRK("rfbi", 0x4832a800, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1430 SYSC_QUIRK("rfbi", 0x58002000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1431 SYSC_QUIRK("scm", 0, 0, 0x10, -ENODEV
, 0x40000900, 0xffffffff, 0),
1432 SYSC_QUIRK("scm", 0, 0, -ENODEV
, -ENODEV
, 0x4e8b0100, 0xffffffff, 0),
1433 SYSC_QUIRK("scm", 0, 0, -ENODEV
, -ENODEV
, 0x4f000100, 0xffffffff, 0),
1434 SYSC_QUIRK("scm", 0, 0, -ENODEV
, -ENODEV
, 0x40000900, 0xffffffff, 0),
1435 SYSC_QUIRK("scrm", 0, 0, -ENODEV
, -ENODEV
, 0x00000010, 0xffffffff, 0),
1436 SYSC_QUIRK("sdio", 0, 0, 0x10, -ENODEV
, 0x40202301, 0xffff0ff0, 0),
1437 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
1438 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
1439 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV
, 0x40000902, 0xffffffff, 0),
1440 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV
, 0x40002903, 0xffffffff, 0),
1441 SYSC_QUIRK("spinlock", 0, 0, 0x10, -ENODEV
, 0x50020000, 0xffffffff, 0),
1442 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -ENODEV
, 0x00000020, 0xffffffff, 0),
1443 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV
, 0x00000060, 0xffffffff, 0),
1444 SYSC_QUIRK("tpcc", 0, 0, -ENODEV
, -ENODEV
, 0x40014c00, 0xffffffff, 0),
1445 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
1446 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
1447 SYSC_QUIRK("venc", 0x58003000, 0, -ENODEV
, -ENODEV
, 0x00000002, 0xffffffff, 0),
1448 SYSC_QUIRK("vfpe", 0, 0, 0x104, -ENODEV
, 0x4d001200, 0xffffffff, 0),
1453 * Early quirks based on module base and register offsets only that are
1454 * needed before the module revision can be read
1456 static void sysc_init_early_quirks(struct sysc
*ddata
)
1458 const struct sysc_revision_quirk
*q
;
1461 for (i
= 0; i
< ARRAY_SIZE(sysc_revision_quirks
); i
++) {
1462 q
= &sysc_revision_quirks
[i
];
1467 if (q
->base
!= ddata
->module_pa
)
1470 if (q
->rev_offset
!= ddata
->offsets
[SYSC_REVISION
])
1473 if (q
->sysc_offset
!= ddata
->offsets
[SYSC_SYSCONFIG
])
1476 if (q
->syss_offset
!= ddata
->offsets
[SYSC_SYSSTATUS
])
1479 ddata
->name
= q
->name
;
1480 ddata
->cfg
.quirks
|= q
->quirks
;
1484 /* Quirks that also consider the revision register value */
1485 static void sysc_init_revision_quirks(struct sysc
*ddata
)
1487 const struct sysc_revision_quirk
*q
;
1490 for (i
= 0; i
< ARRAY_SIZE(sysc_revision_quirks
); i
++) {
1491 q
= &sysc_revision_quirks
[i
];
1493 if (q
->base
&& q
->base
!= ddata
->module_pa
)
1496 if (q
->rev_offset
!= ddata
->offsets
[SYSC_REVISION
])
1499 if (q
->sysc_offset
!= ddata
->offsets
[SYSC_SYSCONFIG
])
1502 if (q
->syss_offset
!= ddata
->offsets
[SYSC_SYSSTATUS
])
1505 if (q
->revision
== ddata
->revision
||
1506 (q
->revision
& q
->revision_mask
) ==
1507 (ddata
->revision
& q
->revision_mask
)) {
1508 ddata
->name
= q
->name
;
1509 ddata
->cfg
.quirks
|= q
->quirks
;
1514 /* 1-wire needs module's internal clocks enabled for reset */
1515 static void sysc_pre_reset_quirk_hdq1w(struct sysc
*ddata
)
1517 int offset
= 0x0c; /* HDQ_CTRL_STATUS */
1520 val
= sysc_read(ddata
, offset
);
1522 sysc_write(ddata
, offset
, val
);
1525 /* AESS (Audio Engine SubSystem) needs autogating set after enable */
1526 static void sysc_module_enable_quirk_aess(struct sysc
*ddata
)
1528 int offset
= 0x7c; /* AESS_AUTO_GATING_ENABLE */
1530 sysc_write(ddata
, offset
, 1);
1533 /* I2C needs to be disabled for reset */
1534 static void sysc_clk_quirk_i2c(struct sysc
*ddata
, bool enable
)
1539 /* I2C_CON, omap2/3 is different from omap4 and later */
1540 if ((ddata
->revision
& 0xffffff00) == 0x001f0000)
1546 val
= sysc_read(ddata
, offset
);
1551 sysc_write(ddata
, offset
, val
);
1554 static void sysc_pre_reset_quirk_i2c(struct sysc
*ddata
)
1556 sysc_clk_quirk_i2c(ddata
, false);
1559 static void sysc_post_reset_quirk_i2c(struct sysc
*ddata
)
1561 sysc_clk_quirk_i2c(ddata
, true);
1564 /* RTC on am3 and 4 needs to be unlocked and locked for sysconfig */
1565 static void sysc_quirk_rtc(struct sysc
*ddata
, bool lock
)
1567 u32 val
, kick0_val
= 0, kick1_val
= 0;
1568 unsigned long flags
;
1572 kick0_val
= 0x83e70b13;
1573 kick1_val
= 0x95a4f1e0;
1576 local_irq_save(flags
);
1577 /* RTC_STATUS BUSY bit may stay active for 1/32768 seconds (~30 usec) */
1578 error
= readl_poll_timeout_atomic(ddata
->module_va
+ 0x44, val
,
1579 !(val
& BIT(0)), 100, 50);
1581 dev_warn(ddata
->dev
, "rtc busy timeout\n");
1582 /* Now we have ~15 microseconds to read/write various registers */
1583 sysc_write(ddata
, 0x6c, kick0_val
);
1584 sysc_write(ddata
, 0x70, kick1_val
);
1585 local_irq_restore(flags
);
1588 static void sysc_module_unlock_quirk_rtc(struct sysc
*ddata
)
1590 sysc_quirk_rtc(ddata
, false);
1593 static void sysc_module_lock_quirk_rtc(struct sysc
*ddata
)
1595 sysc_quirk_rtc(ddata
, true);
1598 /* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */
1599 static void sysc_module_enable_quirk_sgx(struct sysc
*ddata
)
1601 int offset
= 0xff08; /* OCP_DEBUG_CONFIG */
1602 u32 val
= BIT(31); /* THALIA_INT_BYPASS */
1604 sysc_write(ddata
, offset
, val
);
1607 /* Watchdog timer needs a disable sequence after reset */
1608 static void sysc_reset_done_quirk_wdt(struct sysc
*ddata
)
1610 int wps
, spr
, error
;
1616 sysc_write(ddata
, spr
, 0xaaaa);
1617 error
= readl_poll_timeout(ddata
->module_va
+ wps
, val
,
1619 MAX_MODULE_SOFTRESET_WAIT
);
1621 dev_warn(ddata
->dev
, "wdt disable step1 failed\n");
1623 sysc_write(ddata
, spr
, 0x5555);
1624 error
= readl_poll_timeout(ddata
->module_va
+ wps
, val
,
1626 MAX_MODULE_SOFTRESET_WAIT
);
1628 dev_warn(ddata
->dev
, "wdt disable step2 failed\n");
1631 static void sysc_init_module_quirks(struct sysc
*ddata
)
1633 if (ddata
->legacy_mode
|| !ddata
->name
)
1636 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_HDQ1W
) {
1637 ddata
->pre_reset_quirk
= sysc_pre_reset_quirk_hdq1w
;
1642 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_I2C
) {
1643 ddata
->pre_reset_quirk
= sysc_pre_reset_quirk_i2c
;
1644 ddata
->post_reset_quirk
= sysc_post_reset_quirk_i2c
;
1649 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_AESS
)
1650 ddata
->module_enable_quirk
= sysc_module_enable_quirk_aess
;
1652 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_RTC_UNLOCK
) {
1653 ddata
->module_unlock_quirk
= sysc_module_unlock_quirk_rtc
;
1654 ddata
->module_lock_quirk
= sysc_module_lock_quirk_rtc
;
1659 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_SGX
)
1660 ddata
->module_enable_quirk
= sysc_module_enable_quirk_sgx
;
1662 if (ddata
->cfg
.quirks
& SYSC_MODULE_QUIRK_WDT
) {
1663 ddata
->reset_done_quirk
= sysc_reset_done_quirk_wdt
;
1664 ddata
->module_disable_quirk
= sysc_reset_done_quirk_wdt
;
1668 static int sysc_clockdomain_init(struct sysc
*ddata
)
1670 struct ti_sysc_platform_data
*pdata
= dev_get_platdata(ddata
->dev
);
1671 struct clk
*fck
= NULL
, *ick
= NULL
;
1674 if (!pdata
|| !pdata
->init_clockdomain
)
1677 switch (ddata
->nr_clocks
) {
1679 ick
= ddata
->clocks
[SYSC_ICK
];
1682 fck
= ddata
->clocks
[SYSC_FCK
];
1688 error
= pdata
->init_clockdomain(ddata
->dev
, fck
, ick
, &ddata
->cookie
);
1689 if (!error
|| error
== -ENODEV
)
1696 * Note that pdata->init_module() typically does a reset first. After
1697 * pdata->init_module() is done, PM runtime can be used for the interconnect
1700 static int sysc_legacy_init(struct sysc
*ddata
)
1702 struct ti_sysc_platform_data
*pdata
= dev_get_platdata(ddata
->dev
);
1705 if (!pdata
|| !pdata
->init_module
)
1708 error
= pdata
->init_module(ddata
->dev
, ddata
->mdata
, &ddata
->cookie
);
1709 if (error
== -EEXIST
)
1716 * sysc_rstctrl_reset_deassert - deassert rstctrl reset
1717 * @ddata: device driver data
1718 * @reset: reset before deassert
1720 * A module can have both OCP softreset control and external rstctrl.
1721 * If more complicated rstctrl resets are needed, please handle these
1722 * directly from the child device driver and map only the module reset
1723 * for the parent interconnect target module device.
1725 * Automatic reset of the module on init can be skipped with the
1726 * "ti,no-reset-on-init" device tree property.
1728 static int sysc_rstctrl_reset_deassert(struct sysc
*ddata
, bool reset
)
1736 error
= reset_control_assert(ddata
->rsts
);
1741 reset_control_deassert(ddata
->rsts
);
1747 * Note that the caller must ensure the interconnect target module is enabled
1748 * before calling reset. Otherwise reset will not complete.
1750 static int sysc_reset(struct sysc
*ddata
)
1752 int sysc_offset
, sysc_val
, error
;
1755 sysc_offset
= ddata
->offsets
[SYSC_SYSCONFIG
];
1757 if (ddata
->legacy_mode
|| sysc_offset
< 0 ||
1758 ddata
->cap
->regbits
->srst_shift
< 0 ||
1759 ddata
->cfg
.quirks
& SYSC_QUIRK_NO_RESET_ON_INIT
)
1762 sysc_mask
= BIT(ddata
->cap
->regbits
->srst_shift
);
1764 if (ddata
->pre_reset_quirk
)
1765 ddata
->pre_reset_quirk(ddata
);
1767 sysc_val
= sysc_read_sysconfig(ddata
);
1768 sysc_val
|= sysc_mask
;
1769 sysc_write(ddata
, sysc_offset
, sysc_val
);
1771 if (ddata
->cfg
.srst_udelay
)
1772 usleep_range(ddata
->cfg
.srst_udelay
,
1773 ddata
->cfg
.srst_udelay
* 2);
1775 if (ddata
->post_reset_quirk
)
1776 ddata
->post_reset_quirk(ddata
);
1778 error
= sysc_wait_softreset(ddata
);
1780 dev_warn(ddata
->dev
, "OCP softreset timed out\n");
1782 if (ddata
->reset_done_quirk
)
1783 ddata
->reset_done_quirk(ddata
);
1789 * At this point the module is configured enough to read the revision but
1790 * module may not be completely configured yet to use PM runtime. Enable
1791 * all clocks directly during init to configure the quirks needed for PM
1792 * runtime based on the revision register.
1794 static int sysc_init_module(struct sysc
*ddata
)
1797 bool manage_clocks
= true;
1799 error
= sysc_rstctrl_reset_deassert(ddata
, false);
1803 if (ddata
->cfg
.quirks
&
1804 (SYSC_QUIRK_NO_IDLE
| SYSC_QUIRK_NO_IDLE_ON_INIT
))
1805 manage_clocks
= false;
1807 error
= sysc_clockdomain_init(ddata
);
1811 sysc_clkdm_deny_idle(ddata
);
1814 * Always enable clocks. The bootloader may or may not have enabled
1815 * the related clocks.
1817 error
= sysc_enable_opt_clocks(ddata
);
1821 error
= sysc_enable_main_clocks(ddata
);
1823 goto err_opt_clocks
;
1825 if (!(ddata
->cfg
.quirks
& SYSC_QUIRK_NO_RESET_ON_INIT
)) {
1826 error
= sysc_rstctrl_reset_deassert(ddata
, true);
1828 goto err_main_clocks
;
1831 ddata
->revision
= sysc_read_revision(ddata
);
1832 sysc_init_revision_quirks(ddata
);
1833 sysc_init_module_quirks(ddata
);
1835 if (ddata
->legacy_mode
) {
1836 error
= sysc_legacy_init(ddata
);
1838 goto err_main_clocks
;
1841 if (!ddata
->legacy_mode
) {
1842 error
= sysc_enable_module(ddata
->dev
);
1844 goto err_main_clocks
;
1847 error
= sysc_reset(ddata
);
1849 dev_err(ddata
->dev
, "Reset failed with %d\n", error
);
1851 if (!ddata
->legacy_mode
&& manage_clocks
)
1852 sysc_disable_module(ddata
->dev
);
1856 sysc_disable_main_clocks(ddata
);
1858 /* No re-enable of clockdomain autoidle to prevent module autoidle */
1859 if (manage_clocks
) {
1860 sysc_disable_opt_clocks(ddata
);
1861 sysc_clkdm_allow_idle(ddata
);
1867 static int sysc_init_sysc_mask(struct sysc
*ddata
)
1869 struct device_node
*np
= ddata
->dev
->of_node
;
1873 error
= of_property_read_u32(np
, "ti,sysc-mask", &val
);
1877 ddata
->cfg
.sysc_val
= val
& ddata
->cap
->sysc_mask
;
1882 static int sysc_init_idlemode(struct sysc
*ddata
, u8
*idlemodes
,
1885 struct device_node
*np
= ddata
->dev
->of_node
;
1886 struct property
*prop
;
1890 of_property_for_each_u32(np
, name
, prop
, p
, val
) {
1891 if (val
>= SYSC_NR_IDLEMODES
) {
1892 dev_err(ddata
->dev
, "invalid idlemode: %i\n", val
);
1895 *idlemodes
|= (1 << val
);
1901 static int sysc_init_idlemodes(struct sysc
*ddata
)
1905 error
= sysc_init_idlemode(ddata
, &ddata
->cfg
.midlemodes
,
1910 error
= sysc_init_idlemode(ddata
, &ddata
->cfg
.sidlemodes
,
1919 * Only some devices on omap4 and later have SYSCONFIG reset done
1920 * bit. We can detect this if there is no SYSSTATUS at all, or the
1921 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
1922 * have multiple bits for the child devices like OHCI and EHCI.
1923 * Depends on SYSC being parsed first.
1925 static int sysc_init_syss_mask(struct sysc
*ddata
)
1927 struct device_node
*np
= ddata
->dev
->of_node
;
1931 error
= of_property_read_u32(np
, "ti,syss-mask", &val
);
1933 if ((ddata
->cap
->type
== TI_SYSC_OMAP4
||
1934 ddata
->cap
->type
== TI_SYSC_OMAP4_TIMER
) &&
1935 (ddata
->cfg
.sysc_val
& SYSC_OMAP4_SOFTRESET
))
1936 ddata
->cfg
.quirks
|= SYSC_QUIRK_RESET_STATUS
;
1941 if (!(val
& 1) && (ddata
->cfg
.sysc_val
& SYSC_OMAP4_SOFTRESET
))
1942 ddata
->cfg
.quirks
|= SYSC_QUIRK_RESET_STATUS
;
1944 ddata
->cfg
.syss_mask
= val
;
1950 * Many child device drivers need to have fck and opt clocks available
1951 * to get the clock rate for device internal configuration etc.
1953 static int sysc_child_add_named_clock(struct sysc
*ddata
,
1954 struct device
*child
,
1958 struct clk_lookup
*l
;
1964 clk
= clk_get(child
, name
);
1971 clk
= clk_get(ddata
->dev
, name
);
1975 l
= clkdev_create(clk
, name
, dev_name(child
));
1984 static int sysc_child_add_clocks(struct sysc
*ddata
,
1985 struct device
*child
)
1989 for (i
= 0; i
< ddata
->nr_clocks
; i
++) {
1990 error
= sysc_child_add_named_clock(ddata
,
1992 ddata
->clock_roles
[i
]);
1993 if (error
&& error
!= -EEXIST
) {
1994 dev_err(ddata
->dev
, "could not add child clock %s: %i\n",
1995 ddata
->clock_roles
[i
], error
);
2004 static struct device_type sysc_device_type
= {
2007 static struct sysc
*sysc_child_to_parent(struct device
*dev
)
2009 struct device
*parent
= dev
->parent
;
2011 if (!parent
|| parent
->type
!= &sysc_device_type
)
2014 return dev_get_drvdata(parent
);
2017 static int __maybe_unused
sysc_child_runtime_suspend(struct device
*dev
)
2022 ddata
= sysc_child_to_parent(dev
);
2024 error
= pm_generic_runtime_suspend(dev
);
2028 if (!ddata
->enabled
)
2031 return sysc_runtime_suspend(ddata
->dev
);
2034 static int __maybe_unused
sysc_child_runtime_resume(struct device
*dev
)
2039 ddata
= sysc_child_to_parent(dev
);
2041 if (!ddata
->enabled
) {
2042 error
= sysc_runtime_resume(ddata
->dev
);
2045 "%s error: %i\n", __func__
, error
);
2048 return pm_generic_runtime_resume(dev
);
2051 #ifdef CONFIG_PM_SLEEP
2052 static int sysc_child_suspend_noirq(struct device
*dev
)
2057 ddata
= sysc_child_to_parent(dev
);
2059 dev_dbg(ddata
->dev
, "%s %s\n", __func__
,
2060 ddata
->name
? ddata
->name
: "");
2062 error
= pm_generic_suspend_noirq(dev
);
2064 dev_err(dev
, "%s error at %i: %i\n",
2065 __func__
, __LINE__
, error
);
2070 if (!pm_runtime_status_suspended(dev
)) {
2071 error
= pm_generic_runtime_suspend(dev
);
2073 dev_dbg(dev
, "%s busy at %i: %i\n",
2074 __func__
, __LINE__
, error
);
2079 error
= sysc_runtime_suspend(ddata
->dev
);
2081 dev_err(dev
, "%s error at %i: %i\n",
2082 __func__
, __LINE__
, error
);
2087 ddata
->child_needs_resume
= true;
2093 static int sysc_child_resume_noirq(struct device
*dev
)
2098 ddata
= sysc_child_to_parent(dev
);
2100 dev_dbg(ddata
->dev
, "%s %s\n", __func__
,
2101 ddata
->name
? ddata
->name
: "");
2103 if (ddata
->child_needs_resume
) {
2104 ddata
->child_needs_resume
= false;
2106 error
= sysc_runtime_resume(ddata
->dev
);
2109 "%s runtime resume error: %i\n",
2112 error
= pm_generic_runtime_resume(dev
);
2115 "%s generic runtime resume: %i\n",
2119 return pm_generic_resume_noirq(dev
);
2123 static struct dev_pm_domain sysc_child_pm_domain
= {
2125 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend
,
2126 sysc_child_runtime_resume
,
2128 USE_PLATFORM_PM_SLEEP_OPS
2129 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq
,
2130 sysc_child_resume_noirq
)
2135 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
2136 * @ddata: device driver data
2137 * @child: child device driver
2139 * Allow idle for child devices as done with _od_runtime_suspend().
2140 * Otherwise many child devices will not idle because of the permanent
2141 * parent usecount set in pm_runtime_irq_safe().
2143 * Note that the long term solution is to just modify the child device
2144 * drivers to not set pm_runtime_irq_safe() and then this can be just
2147 static void sysc_legacy_idle_quirk(struct sysc
*ddata
, struct device
*child
)
2149 if (ddata
->cfg
.quirks
& SYSC_QUIRK_LEGACY_IDLE
)
2150 dev_pm_domain_set(child
, &sysc_child_pm_domain
);
2153 static int sysc_notifier_call(struct notifier_block
*nb
,
2154 unsigned long event
, void *device
)
2156 struct device
*dev
= device
;
2160 ddata
= sysc_child_to_parent(dev
);
2165 case BUS_NOTIFY_ADD_DEVICE
:
2166 error
= sysc_child_add_clocks(ddata
, dev
);
2169 sysc_legacy_idle_quirk(ddata
, dev
);
2178 static struct notifier_block sysc_nb
= {
2179 .notifier_call
= sysc_notifier_call
,
2182 /* Device tree configured quirks */
2183 struct sysc_dts_quirk
{
2188 static const struct sysc_dts_quirk sysc_dts_quirks
[] = {
2189 { .name
= "ti,no-idle-on-init",
2190 .mask
= SYSC_QUIRK_NO_IDLE_ON_INIT
, },
2191 { .name
= "ti,no-reset-on-init",
2192 .mask
= SYSC_QUIRK_NO_RESET_ON_INIT
, },
2193 { .name
= "ti,no-idle",
2194 .mask
= SYSC_QUIRK_NO_IDLE
, },
2197 static void sysc_parse_dts_quirks(struct sysc
*ddata
, struct device_node
*np
,
2200 const struct property
*prop
;
2203 for (i
= 0; i
< ARRAY_SIZE(sysc_dts_quirks
); i
++) {
2204 const char *name
= sysc_dts_quirks
[i
].name
;
2206 prop
= of_get_property(np
, name
, &len
);
2210 ddata
->cfg
.quirks
|= sysc_dts_quirks
[i
].mask
;
2212 dev_warn(ddata
->dev
,
2213 "dts flag should be at module level for %s\n",
2219 static int sysc_init_dts_quirks(struct sysc
*ddata
)
2221 struct device_node
*np
= ddata
->dev
->of_node
;
2225 ddata
->legacy_mode
= of_get_property(np
, "ti,hwmods", NULL
);
2227 sysc_parse_dts_quirks(ddata
, np
, false);
2228 error
= of_property_read_u32(np
, "ti,sysc-delay-us", &val
);
2231 dev_warn(ddata
->dev
, "bad ti,sysc-delay-us: %i\n",
2235 ddata
->cfg
.srst_udelay
= (u8
)val
;
2241 static void sysc_unprepare(struct sysc
*ddata
)
2248 for (i
= 0; i
< SYSC_MAX_CLOCKS
; i
++) {
2249 if (!IS_ERR_OR_NULL(ddata
->clocks
[i
]))
2250 clk_unprepare(ddata
->clocks
[i
]);
2255 * Common sysc register bits found on omap2, also known as type1
2257 static const struct sysc_regbits sysc_regbits_omap2
= {
2258 .dmadisable_shift
= -ENODEV
,
2265 .autoidle_shift
= 0,
2268 static const struct sysc_capabilities sysc_omap2
= {
2269 .type
= TI_SYSC_OMAP2
,
2270 .sysc_mask
= SYSC_OMAP2_CLOCKACTIVITY
| SYSC_OMAP2_EMUFREE
|
2271 SYSC_OMAP2_ENAWAKEUP
| SYSC_OMAP2_SOFTRESET
|
2272 SYSC_OMAP2_AUTOIDLE
,
2273 .regbits
= &sysc_regbits_omap2
,
2276 /* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2277 static const struct sysc_capabilities sysc_omap2_timer
= {
2278 .type
= TI_SYSC_OMAP2_TIMER
,
2279 .sysc_mask
= SYSC_OMAP2_CLOCKACTIVITY
| SYSC_OMAP2_EMUFREE
|
2280 SYSC_OMAP2_ENAWAKEUP
| SYSC_OMAP2_SOFTRESET
|
2281 SYSC_OMAP2_AUTOIDLE
,
2282 .regbits
= &sysc_regbits_omap2
,
2283 .mod_quirks
= SYSC_QUIRK_USE_CLOCKACT
,
2287 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2288 * with different sidle position
2290 static const struct sysc_regbits sysc_regbits_omap3_sham
= {
2291 .dmadisable_shift
= -ENODEV
,
2292 .midle_shift
= -ENODEV
,
2294 .clkact_shift
= -ENODEV
,
2295 .enwkup_shift
= -ENODEV
,
2297 .autoidle_shift
= 0,
2298 .emufree_shift
= -ENODEV
,
2301 static const struct sysc_capabilities sysc_omap3_sham
= {
2302 .type
= TI_SYSC_OMAP3_SHAM
,
2303 .sysc_mask
= SYSC_OMAP2_SOFTRESET
| SYSC_OMAP2_AUTOIDLE
,
2304 .regbits
= &sysc_regbits_omap3_sham
,
2308 * AES register bits found on omap3 and later, a variant of
2309 * sysc_regbits_omap2 with different sidle position
2311 static const struct sysc_regbits sysc_regbits_omap3_aes
= {
2312 .dmadisable_shift
= -ENODEV
,
2313 .midle_shift
= -ENODEV
,
2315 .clkact_shift
= -ENODEV
,
2316 .enwkup_shift
= -ENODEV
,
2318 .autoidle_shift
= 0,
2319 .emufree_shift
= -ENODEV
,
2322 static const struct sysc_capabilities sysc_omap3_aes
= {
2323 .type
= TI_SYSC_OMAP3_AES
,
2324 .sysc_mask
= SYSC_OMAP2_SOFTRESET
| SYSC_OMAP2_AUTOIDLE
,
2325 .regbits
= &sysc_regbits_omap3_aes
,
2329 * Common sysc register bits found on omap4, also known as type2
2331 static const struct sysc_regbits sysc_regbits_omap4
= {
2332 .dmadisable_shift
= 16,
2335 .clkact_shift
= -ENODEV
,
2336 .enwkup_shift
= -ENODEV
,
2339 .autoidle_shift
= -ENODEV
,
2342 static const struct sysc_capabilities sysc_omap4
= {
2343 .type
= TI_SYSC_OMAP4
,
2344 .sysc_mask
= SYSC_OMAP4_DMADISABLE
| SYSC_OMAP4_FREEEMU
|
2345 SYSC_OMAP4_SOFTRESET
,
2346 .regbits
= &sysc_regbits_omap4
,
2349 static const struct sysc_capabilities sysc_omap4_timer
= {
2350 .type
= TI_SYSC_OMAP4_TIMER
,
2351 .sysc_mask
= SYSC_OMAP4_DMADISABLE
| SYSC_OMAP4_FREEEMU
|
2352 SYSC_OMAP4_SOFTRESET
,
2353 .regbits
= &sysc_regbits_omap4
,
2357 * Common sysc register bits found on omap4, also known as type3
2359 static const struct sysc_regbits sysc_regbits_omap4_simple
= {
2360 .dmadisable_shift
= -ENODEV
,
2363 .clkact_shift
= -ENODEV
,
2364 .enwkup_shift
= -ENODEV
,
2365 .srst_shift
= -ENODEV
,
2366 .emufree_shift
= -ENODEV
,
2367 .autoidle_shift
= -ENODEV
,
2370 static const struct sysc_capabilities sysc_omap4_simple
= {
2371 .type
= TI_SYSC_OMAP4_SIMPLE
,
2372 .regbits
= &sysc_regbits_omap4_simple
,
2376 * SmartReflex sysc found on omap34xx
2378 static const struct sysc_regbits sysc_regbits_omap34xx_sr
= {
2379 .dmadisable_shift
= -ENODEV
,
2380 .midle_shift
= -ENODEV
,
2381 .sidle_shift
= -ENODEV
,
2383 .enwkup_shift
= -ENODEV
,
2384 .srst_shift
= -ENODEV
,
2385 .emufree_shift
= -ENODEV
,
2386 .autoidle_shift
= -ENODEV
,
2389 static const struct sysc_capabilities sysc_34xx_sr
= {
2390 .type
= TI_SYSC_OMAP34XX_SR
,
2391 .sysc_mask
= SYSC_OMAP2_CLOCKACTIVITY
,
2392 .regbits
= &sysc_regbits_omap34xx_sr
,
2393 .mod_quirks
= SYSC_QUIRK_USE_CLOCKACT
| SYSC_QUIRK_UNCACHED
|
2394 SYSC_QUIRK_LEGACY_IDLE
,
2398 * SmartReflex sysc found on omap36xx and later
2400 static const struct sysc_regbits sysc_regbits_omap36xx_sr
= {
2401 .dmadisable_shift
= -ENODEV
,
2402 .midle_shift
= -ENODEV
,
2404 .clkact_shift
= -ENODEV
,
2406 .srst_shift
= -ENODEV
,
2407 .emufree_shift
= -ENODEV
,
2408 .autoidle_shift
= -ENODEV
,
2411 static const struct sysc_capabilities sysc_36xx_sr
= {
2412 .type
= TI_SYSC_OMAP36XX_SR
,
2413 .sysc_mask
= SYSC_OMAP3_SR_ENAWAKEUP
,
2414 .regbits
= &sysc_regbits_omap36xx_sr
,
2415 .mod_quirks
= SYSC_QUIRK_UNCACHED
| SYSC_QUIRK_LEGACY_IDLE
,
2418 static const struct sysc_capabilities sysc_omap4_sr
= {
2419 .type
= TI_SYSC_OMAP4_SR
,
2420 .regbits
= &sysc_regbits_omap36xx_sr
,
2421 .mod_quirks
= SYSC_QUIRK_LEGACY_IDLE
,
2425 * McASP register bits found on omap4 and later
2427 static const struct sysc_regbits sysc_regbits_omap4_mcasp
= {
2428 .dmadisable_shift
= -ENODEV
,
2429 .midle_shift
= -ENODEV
,
2431 .clkact_shift
= -ENODEV
,
2432 .enwkup_shift
= -ENODEV
,
2433 .srst_shift
= -ENODEV
,
2434 .emufree_shift
= -ENODEV
,
2435 .autoidle_shift
= -ENODEV
,
2438 static const struct sysc_capabilities sysc_omap4_mcasp
= {
2439 .type
= TI_SYSC_OMAP4_MCASP
,
2440 .regbits
= &sysc_regbits_omap4_mcasp
,
2441 .mod_quirks
= SYSC_QUIRK_OPT_CLKS_NEEDED
,
2445 * McASP found on dra7 and later
2447 static const struct sysc_capabilities sysc_dra7_mcasp
= {
2448 .type
= TI_SYSC_OMAP4_SIMPLE
,
2449 .regbits
= &sysc_regbits_omap4_simple
,
2450 .mod_quirks
= SYSC_QUIRK_OPT_CLKS_NEEDED
,
2454 * FS USB host found on omap4 and later
2456 static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs
= {
2457 .dmadisable_shift
= -ENODEV
,
2458 .midle_shift
= -ENODEV
,
2460 .clkact_shift
= -ENODEV
,
2462 .srst_shift
= -ENODEV
,
2463 .emufree_shift
= -ENODEV
,
2464 .autoidle_shift
= -ENODEV
,
2467 static const struct sysc_capabilities sysc_omap4_usb_host_fs
= {
2468 .type
= TI_SYSC_OMAP4_USB_HOST_FS
,
2469 .sysc_mask
= SYSC_OMAP2_ENAWAKEUP
,
2470 .regbits
= &sysc_regbits_omap4_usb_host_fs
,
2473 static const struct sysc_regbits sysc_regbits_dra7_mcan
= {
2474 .dmadisable_shift
= -ENODEV
,
2475 .midle_shift
= -ENODEV
,
2476 .sidle_shift
= -ENODEV
,
2477 .clkact_shift
= -ENODEV
,
2480 .emufree_shift
= -ENODEV
,
2481 .autoidle_shift
= -ENODEV
,
2484 static const struct sysc_capabilities sysc_dra7_mcan
= {
2485 .type
= TI_SYSC_DRA7_MCAN
,
2486 .sysc_mask
= SYSC_DRA7_MCAN_ENAWAKEUP
| SYSC_OMAP4_SOFTRESET
,
2487 .regbits
= &sysc_regbits_dra7_mcan
,
2488 .mod_quirks
= SYSS_QUIRK_RESETDONE_INVERTED
,
2491 static int sysc_init_pdata(struct sysc
*ddata
)
2493 struct ti_sysc_platform_data
*pdata
= dev_get_platdata(ddata
->dev
);
2494 struct ti_sysc_module_data
*mdata
;
2499 mdata
= devm_kzalloc(ddata
->dev
, sizeof(*mdata
), GFP_KERNEL
);
2503 if (ddata
->legacy_mode
) {
2504 mdata
->name
= ddata
->legacy_mode
;
2505 mdata
->module_pa
= ddata
->module_pa
;
2506 mdata
->module_size
= ddata
->module_size
;
2507 mdata
->offsets
= ddata
->offsets
;
2508 mdata
->nr_offsets
= SYSC_MAX_REGS
;
2509 mdata
->cap
= ddata
->cap
;
2510 mdata
->cfg
= &ddata
->cfg
;
2513 ddata
->mdata
= mdata
;
2518 static int sysc_init_match(struct sysc
*ddata
)
2520 const struct sysc_capabilities
*cap
;
2522 cap
= of_device_get_match_data(ddata
->dev
);
2528 ddata
->cfg
.quirks
|= ddata
->cap
->mod_quirks
;
2533 static void ti_sysc_idle(struct work_struct
*work
)
2537 ddata
= container_of(work
, struct sysc
, idle_work
.work
);
2540 * One time decrement of clock usage counts if left on from init.
2541 * Note that we disable opt clocks unconditionally in this case
2542 * as they are enabled unconditionally during init without
2543 * considering sysc_opt_clks_needed() at that point.
2545 if (ddata
->cfg
.quirks
& (SYSC_QUIRK_NO_IDLE
|
2546 SYSC_QUIRK_NO_IDLE_ON_INIT
)) {
2547 sysc_disable_main_clocks(ddata
);
2548 sysc_disable_opt_clocks(ddata
);
2549 sysc_clkdm_allow_idle(ddata
);
2552 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
2553 if (ddata
->cfg
.quirks
& SYSC_QUIRK_NO_IDLE
)
2557 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
2558 * and SYSC_QUIRK_NO_RESET_ON_INIT
2560 if (pm_runtime_active(ddata
->dev
))
2561 pm_runtime_put_sync(ddata
->dev
);
2564 static const struct of_device_id sysc_match_table
[] = {
2565 { .compatible
= "simple-bus", },
2569 static int sysc_probe(struct platform_device
*pdev
)
2571 struct ti_sysc_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
2575 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
2579 ddata
->dev
= &pdev
->dev
;
2580 platform_set_drvdata(pdev
, ddata
);
2582 error
= sysc_init_match(ddata
);
2586 error
= sysc_init_dts_quirks(ddata
);
2590 error
= sysc_map_and_check_registers(ddata
);
2594 error
= sysc_init_sysc_mask(ddata
);
2598 error
= sysc_init_idlemodes(ddata
);
2602 error
= sysc_init_syss_mask(ddata
);
2606 error
= sysc_init_pdata(ddata
);
2610 sysc_init_early_quirks(ddata
);
2612 error
= sysc_get_clocks(ddata
);
2616 error
= sysc_init_resets(ddata
);
2620 error
= sysc_init_module(ddata
);
2624 pm_runtime_enable(ddata
->dev
);
2625 error
= pm_runtime_get_sync(ddata
->dev
);
2627 pm_runtime_put_noidle(ddata
->dev
);
2628 pm_runtime_disable(ddata
->dev
);
2632 /* Balance reset counts */
2634 reset_control_assert(ddata
->rsts
);
2636 sysc_show_registers(ddata
);
2638 ddata
->dev
->type
= &sysc_device_type
;
2639 error
= of_platform_populate(ddata
->dev
->of_node
, sysc_match_table
,
2640 pdata
? pdata
->auxdata
: NULL
,
2645 INIT_DELAYED_WORK(&ddata
->idle_work
, ti_sysc_idle
);
2647 /* At least earlycon won't survive without deferred idle */
2648 if (ddata
->cfg
.quirks
& (SYSC_QUIRK_NO_IDLE
|
2649 SYSC_QUIRK_NO_IDLE_ON_INIT
|
2650 SYSC_QUIRK_NO_RESET_ON_INIT
)) {
2651 schedule_delayed_work(&ddata
->idle_work
, 3000);
2653 pm_runtime_put(&pdev
->dev
);
2659 pm_runtime_put_sync(&pdev
->dev
);
2660 pm_runtime_disable(&pdev
->dev
);
2662 sysc_unprepare(ddata
);
2667 static int sysc_remove(struct platform_device
*pdev
)
2669 struct sysc
*ddata
= platform_get_drvdata(pdev
);
2672 cancel_delayed_work_sync(&ddata
->idle_work
);
2674 error
= pm_runtime_get_sync(ddata
->dev
);
2676 pm_runtime_put_noidle(ddata
->dev
);
2677 pm_runtime_disable(ddata
->dev
);
2681 of_platform_depopulate(&pdev
->dev
);
2683 pm_runtime_put_sync(&pdev
->dev
);
2684 pm_runtime_disable(&pdev
->dev
);
2685 reset_control_assert(ddata
->rsts
);
2688 sysc_unprepare(ddata
);
2693 static const struct of_device_id sysc_match
[] = {
2694 { .compatible
= "ti,sysc-omap2", .data
= &sysc_omap2
, },
2695 { .compatible
= "ti,sysc-omap2-timer", .data
= &sysc_omap2_timer
, },
2696 { .compatible
= "ti,sysc-omap4", .data
= &sysc_omap4
, },
2697 { .compatible
= "ti,sysc-omap4-timer", .data
= &sysc_omap4_timer
, },
2698 { .compatible
= "ti,sysc-omap4-simple", .data
= &sysc_omap4_simple
, },
2699 { .compatible
= "ti,sysc-omap3430-sr", .data
= &sysc_34xx_sr
, },
2700 { .compatible
= "ti,sysc-omap3630-sr", .data
= &sysc_36xx_sr
, },
2701 { .compatible
= "ti,sysc-omap4-sr", .data
= &sysc_omap4_sr
, },
2702 { .compatible
= "ti,sysc-omap3-sham", .data
= &sysc_omap3_sham
, },
2703 { .compatible
= "ti,sysc-omap-aes", .data
= &sysc_omap3_aes
, },
2704 { .compatible
= "ti,sysc-mcasp", .data
= &sysc_omap4_mcasp
, },
2705 { .compatible
= "ti,sysc-dra7-mcasp", .data
= &sysc_dra7_mcasp
, },
2706 { .compatible
= "ti,sysc-usb-host-fs",
2707 .data
= &sysc_omap4_usb_host_fs
, },
2708 { .compatible
= "ti,sysc-dra7-mcan", .data
= &sysc_dra7_mcan
, },
2711 MODULE_DEVICE_TABLE(of
, sysc_match
);
2713 static struct platform_driver sysc_driver
= {
2714 .probe
= sysc_probe
,
2715 .remove
= sysc_remove
,
2718 .of_match_table
= sysc_match
,
2723 static int __init
sysc_init(void)
2725 bus_register_notifier(&platform_bus_type
, &sysc_nb
);
2727 return platform_driver_register(&sysc_driver
);
2729 module_init(sysc_init
);
2731 static void __exit
sysc_exit(void)
2733 bus_unregister_notifier(&platform_bus_type
, &sysc_nb
);
2734 platform_driver_unregister(&sysc_driver
);
2736 module_exit(sysc_exit
);
2738 MODULE_DESCRIPTION("TI sysc interconnect target driver");
2739 MODULE_LICENSE("GPL v2");