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/cpu_pm.h>
10 #include <linux/delay.h>
11 #include <linux/list.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/pm_domain.h>
15 #include <linux/pm_runtime.h>
16 #include <linux/reset.h>
17 #include <linux/of_address.h>
18 #include <linux/of_platform.h>
19 #include <linux/slab.h>
20 #include <linux/sys_soc.h>
21 #include <linux/timekeeping.h>
22 #include <linux/iopoll.h>
24 #include <linux/platform_data/ti-sysc.h>
26 #include <dt-bindings/bus/ti-sysc.h>
28 #define DIS_ISP BIT(2)
29 #define DIS_IVA BIT(1)
30 #define DIS_SGX BIT(0)
32 #define SOC_FLAG(match, flag) { .machine = match, .data = (void *)(flag), }
34 #define MAX_MODULE_SOFTRESET_WAIT 10000
54 struct list_head node;
59 struct list_head node;
62 struct sysc_soc_info {
63 unsigned long general_purpose:1;
65 struct mutex list_lock; /* disabled and restored modules list lock */
66 struct list_head disabled_modules;
67 struct list_head restored_modules;
68 struct notifier_block nb;
85 static struct sysc_soc_info *sysc_soc;
86 static const char * const reg_names[] = { "rev", "sysc", "syss", };
87 static const char * const clock_names[SYSC_MAX_CLOCKS] = {
88 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
89 "opt5", "opt6", "opt7",
92 #define SYSC_IDLEMODE_MASK 3
93 #define SYSC_CLOCKACTIVITY_MASK 3
96 * struct sysc - TI sysc interconnect target module registers and capabilities
97 * @dev: struct device pointer
98 * @module_pa: physical address of the interconnect target module
99 * @module_size: size of the interconnect target module
100 * @module_va: virtual address of the interconnect target module
101 * @offsets: register offsets from module base
102 * @mdata: ti-sysc to hwmod translation data for a module
103 * @clocks: clocks used by the interconnect target module
104 * @clock_roles: clock role names for the found clocks
105 * @nr_clocks: number of clocks used by the interconnect target module
106 * @rsts: resets used by the interconnect target module
107 * @legacy_mode: configured for legacy mode if set
108 * @cap: interconnect target module capabilities
109 * @cfg: interconnect target module configuration
110 * @cookie: data used by legacy platform callbacks
111 * @name: name if available
112 * @revision: interconnect target module revision
113 * @sysconfig: saved sysconfig register value
114 * @reserved: target module is reserved and already in use
115 * @enabled: sysc runtime enabled status
116 * @needs_resume: runtime resume needed on resume from suspend
117 * @child_needs_resume: runtime resume needed for child on resume from suspend
118 * @disable_on_idle: status flag used for disabling modules with resets
119 * @idle_work: work structure used to perform delayed idle on a module
120 * @pre_reset_quirk: module specific pre-reset quirk
121 * @post_reset_quirk: module specific post-reset quirk
122 * @reset_done_quirk: module specific reset done quirk
123 * @module_enable_quirk: module specific enable quirk
124 * @module_disable_quirk: module specific disable quirk
125 * @module_unlock_quirk: module specific sysconfig unlock quirk
126 * @module_lock_quirk: module specific sysconfig lock quirk
132 void __iomem *module_va;
133 int offsets[SYSC_MAX_REGS];
134 struct ti_sysc_module_data *mdata;
136 const char **clock_roles;
138 struct reset_control *rsts;
139 const char *legacy_mode;
140 const struct sysc_capabilities *cap;
141 struct sysc_config cfg;
142 struct ti_sysc_cookie cookie;
146 unsigned int reserved:1;
147 unsigned int enabled:1;
148 unsigned int needs_resume:1;
149 unsigned int child_needs_resume:1;
150 struct delayed_work idle_work;
151 void (*pre_reset_quirk)(struct sysc *sysc);
152 void (*post_reset_quirk)(struct sysc *sysc);
153 void (*reset_done_quirk)(struct sysc *sysc);
154 void (*module_enable_quirk)(struct sysc *sysc);
155 void (*module_disable_quirk)(struct sysc *sysc);
156 void (*module_unlock_quirk)(struct sysc *sysc);
157 void (*module_lock_quirk)(struct sysc *sysc);
160 static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
162 static int sysc_reset(struct sysc *ddata);
164 static void sysc_write(struct sysc *ddata, int offset, u32 value)
166 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
167 writew_relaxed(value & 0xffff, ddata->module_va + offset);
169 /* Only i2c revision has LO and HI register with stride of 4 */
170 if (ddata->offsets[SYSC_REVISION] >= 0 &&
171 offset == ddata->offsets[SYSC_REVISION]) {
172 u16 hi = value >> 16;
174 writew_relaxed(hi, ddata->module_va + offset + 4);
180 writel_relaxed(value, ddata->module_va + offset);
183 static u32 sysc_read(struct sysc *ddata, int offset)
185 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
188 val = readw_relaxed(ddata->module_va + offset);
190 /* Only i2c revision has LO and HI register with stride of 4 */
191 if (ddata->offsets[SYSC_REVISION] >= 0 &&
192 offset == ddata->offsets[SYSC_REVISION]) {
193 u16 tmp = readw_relaxed(ddata->module_va + offset + 4);
201 return readl_relaxed(ddata->module_va + offset);
204 static bool sysc_opt_clks_needed(struct sysc *ddata)
206 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
209 static u32 sysc_read_revision(struct sysc *ddata)
211 int offset = ddata->offsets[SYSC_REVISION];
216 return sysc_read(ddata, offset);
219 static u32 sysc_read_sysconfig(struct sysc *ddata)
221 int offset = ddata->offsets[SYSC_SYSCONFIG];
226 return sysc_read(ddata, offset);
229 static u32 sysc_read_sysstatus(struct sysc *ddata)
231 int offset = ddata->offsets[SYSC_SYSSTATUS];
236 return sysc_read(ddata, offset);
239 static int sysc_poll_reset_sysstatus(struct sysc *ddata)
242 u32 syss_done, rstval;
244 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
247 syss_done = ddata->cfg.syss_mask;
249 if (likely(!timekeeping_suspended)) {
250 error = readx_poll_timeout_atomic(sysc_read_sysstatus, ddata,
251 rstval, (rstval & ddata->cfg.syss_mask) ==
252 syss_done, 100, MAX_MODULE_SOFTRESET_WAIT);
254 retries = MAX_MODULE_SOFTRESET_WAIT;
256 rstval = sysc_read_sysstatus(ddata);
257 if ((rstval & ddata->cfg.syss_mask) == syss_done)
259 udelay(2); /* Account for udelay flakeyness */
267 static int sysc_poll_reset_sysconfig(struct sysc *ddata)
270 u32 sysc_mask, rstval;
272 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
274 if (likely(!timekeeping_suspended)) {
275 error = readx_poll_timeout_atomic(sysc_read_sysconfig, ddata,
276 rstval, !(rstval & sysc_mask),
277 100, MAX_MODULE_SOFTRESET_WAIT);
279 retries = MAX_MODULE_SOFTRESET_WAIT;
281 rstval = sysc_read_sysconfig(ddata);
282 if (!(rstval & sysc_mask))
284 udelay(2); /* Account for udelay flakeyness */
292 /* Poll on reset status */
293 static int sysc_wait_softreset(struct sysc *ddata)
295 int syss_offset, error = 0;
297 if (ddata->cap->regbits->srst_shift < 0)
300 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
302 if (syss_offset >= 0)
303 error = sysc_poll_reset_sysstatus(ddata);
304 else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS)
305 error = sysc_poll_reset_sysconfig(ddata);
310 static int sysc_add_named_clock_from_child(struct sysc *ddata,
312 const char *optfck_name)
314 struct device_node *np = ddata->dev->of_node;
315 struct device_node *child;
316 struct clk_lookup *cl;
325 /* Does the clock alias already exist? */
326 clock = of_clk_get_by_name(np, n);
327 if (!IS_ERR(clock)) {
333 child = of_get_next_available_child(np, NULL);
337 clock = devm_get_clk_from_child(ddata->dev, child, name);
339 return PTR_ERR(clock);
342 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
343 * limit for clk_get(). If cl ever needs to be freed, it should be done
344 * with clkdev_drop().
346 cl = kzalloc(sizeof(*cl), GFP_KERNEL);
351 cl->dev_id = dev_name(ddata->dev);
360 static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
362 const char *optfck_name;
365 if (ddata->nr_clocks < SYSC_OPTFCK0)
366 index = SYSC_OPTFCK0;
368 index = ddata->nr_clocks;
373 optfck_name = clock_names[index];
375 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
379 ddata->clock_roles[index] = optfck_name;
385 static int sysc_get_one_clock(struct sysc *ddata, const char *name)
387 int error, i, index = -ENODEV;
389 if (!strncmp(clock_names[SYSC_FCK], name, 3))
391 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
395 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
396 if (!ddata->clocks[i]) {
404 dev_err(ddata->dev, "clock %s not added\n", name);
408 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
409 if (IS_ERR(ddata->clocks[index])) {
410 dev_err(ddata->dev, "clock get error for %s: %li\n",
411 name, PTR_ERR(ddata->clocks[index]));
413 return PTR_ERR(ddata->clocks[index]);
416 error = clk_prepare(ddata->clocks[index]);
418 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
427 static int sysc_get_clocks(struct sysc *ddata)
429 struct device_node *np = ddata->dev->of_node;
430 struct property *prop;
432 int nr_fck = 0, nr_ick = 0, i, error = 0;
434 ddata->clock_roles = devm_kcalloc(ddata->dev,
436 sizeof(*ddata->clock_roles),
438 if (!ddata->clock_roles)
441 of_property_for_each_string(np, "clock-names", prop, name) {
442 if (!strncmp(clock_names[SYSC_FCK], name, 3))
444 if (!strncmp(clock_names[SYSC_ICK], name, 3))
446 ddata->clock_roles[ddata->nr_clocks] = name;
450 if (ddata->nr_clocks < 1)
453 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
454 error = sysc_init_ext_opt_clock(ddata, NULL);
459 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
460 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
465 if (nr_fck > 1 || nr_ick > 1) {
466 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
471 /* Always add a slot for main clocks fck and ick even if unused */
477 ddata->clocks = devm_kcalloc(ddata->dev,
478 ddata->nr_clocks, sizeof(*ddata->clocks),
483 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
484 const char *name = ddata->clock_roles[i];
489 error = sysc_get_one_clock(ddata, name);
497 static int sysc_enable_main_clocks(struct sysc *ddata)
505 for (i = 0; i < SYSC_OPTFCK0; i++) {
506 clock = ddata->clocks[i];
508 /* Main clocks may not have ick */
509 if (IS_ERR_OR_NULL(clock))
512 error = clk_enable(clock);
520 for (i--; i >= 0; i--) {
521 clock = ddata->clocks[i];
523 /* Main clocks may not have ick */
524 if (IS_ERR_OR_NULL(clock))
533 static void sysc_disable_main_clocks(struct sysc *ddata)
541 for (i = 0; i < SYSC_OPTFCK0; i++) {
542 clock = ddata->clocks[i];
543 if (IS_ERR_OR_NULL(clock))
550 static int sysc_enable_opt_clocks(struct sysc *ddata)
555 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
558 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
559 clock = ddata->clocks[i];
561 /* Assume no holes for opt clocks */
562 if (IS_ERR_OR_NULL(clock))
565 error = clk_enable(clock);
573 for (i--; i >= 0; i--) {
574 clock = ddata->clocks[i];
575 if (IS_ERR_OR_NULL(clock))
584 static void sysc_disable_opt_clocks(struct sysc *ddata)
589 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
592 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
593 clock = ddata->clocks[i];
595 /* Assume no holes for opt clocks */
596 if (IS_ERR_OR_NULL(clock))
603 static void sysc_clkdm_deny_idle(struct sysc *ddata)
605 struct ti_sysc_platform_data *pdata;
607 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
610 pdata = dev_get_platdata(ddata->dev);
611 if (pdata && pdata->clkdm_deny_idle)
612 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
615 static void sysc_clkdm_allow_idle(struct sysc *ddata)
617 struct ti_sysc_platform_data *pdata;
619 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
622 pdata = dev_get_platdata(ddata->dev);
623 if (pdata && pdata->clkdm_allow_idle)
624 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
628 * sysc_init_resets - init rstctrl reset line if configured
629 * @ddata: device driver data
631 * See sysc_rstctrl_reset_deassert().
633 static int sysc_init_resets(struct sysc *ddata)
636 devm_reset_control_get_optional_shared(ddata->dev, "rstctrl");
638 return PTR_ERR_OR_ZERO(ddata->rsts);
642 * sysc_parse_and_check_child_range - parses module IO region from ranges
643 * @ddata: device driver data
645 * In general we only need rev, syss, and sysc registers and not the whole
646 * module range. But we do want the offsets for these registers from the
647 * module base. This allows us to check them against the legacy hwmod
648 * platform data. Let's also check the ranges are configured properly.
650 static int sysc_parse_and_check_child_range(struct sysc *ddata)
652 struct device_node *np = ddata->dev->of_node;
653 struct of_range_parser parser;
654 struct of_range range;
657 error = of_range_parser_init(&parser, np);
661 for_each_of_range(&parser, &range) {
662 ddata->module_pa = range.cpu_addr;
663 ddata->module_size = range.size;
670 /* Interconnect instances to probe before l4_per instances */
671 static struct resource early_bus_ranges[] = {
673 { .start = 0x44c00000, .end = 0x44c00000 + 0x300000, },
674 /* omap4/5 and dra7 l4_cfg */
675 { .start = 0x4a000000, .end = 0x4a000000 + 0x300000, },
677 { .start = 0x4a300000, .end = 0x4a300000 + 0x30000, },
678 /* omap5 and dra7 l4_wkup without dra7 dcan segment */
679 { .start = 0x4ae00000, .end = 0x4ae00000 + 0x30000, },
682 static atomic_t sysc_defer = ATOMIC_INIT(10);
685 * sysc_defer_non_critical - defer non_critical interconnect probing
686 * @ddata: device driver data
688 * We want to probe l4_cfg and l4_wkup interconnect instances before any
689 * l4_per instances as l4_per instances depend on resources on l4_cfg and
690 * l4_wkup interconnects.
692 static int sysc_defer_non_critical(struct sysc *ddata)
694 struct resource *res;
697 if (!atomic_read(&sysc_defer))
700 for (i = 0; i < ARRAY_SIZE(early_bus_ranges); i++) {
701 res = &early_bus_ranges[i];
702 if (ddata->module_pa >= res->start &&
703 ddata->module_pa <= res->end) {
704 atomic_set(&sysc_defer, 0);
710 atomic_dec_if_positive(&sysc_defer);
712 return -EPROBE_DEFER;
715 static struct device_node *stdout_path;
717 static void sysc_init_stdout_path(struct sysc *ddata)
719 struct device_node *np = NULL;
722 if (IS_ERR(stdout_path))
728 np = of_find_node_by_path("/chosen");
732 uart = of_get_property(np, "stdout-path", NULL);
736 np = of_find_node_by_path(uart);
745 stdout_path = ERR_PTR(-ENODEV);
748 static void sysc_check_quirk_stdout(struct sysc *ddata,
749 struct device_node *np)
751 sysc_init_stdout_path(ddata);
752 if (np != stdout_path)
755 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
756 SYSC_QUIRK_NO_RESET_ON_INIT;
760 * sysc_check_one_child - check child configuration
761 * @ddata: device driver data
762 * @np: child device node
764 * Let's avoid messy situations where we have new interconnect target
765 * node but children have "ti,hwmods". These belong to the interconnect
766 * target node and are managed by this driver.
768 static void sysc_check_one_child(struct sysc *ddata,
769 struct device_node *np)
773 name = of_get_property(np, "ti,hwmods", NULL);
774 if (name && !of_device_is_compatible(np, "ti,sysc"))
775 dev_warn(ddata->dev, "really a child ti,hwmods property?");
777 sysc_check_quirk_stdout(ddata, np);
778 sysc_parse_dts_quirks(ddata, np, true);
781 static void sysc_check_children(struct sysc *ddata)
783 struct device_node *child;
785 for_each_child_of_node(ddata->dev->of_node, child)
786 sysc_check_one_child(ddata, child);
790 * So far only I2C uses 16-bit read access with clockactivity with revision
791 * in two registers with stride of 4. We can detect this based on the rev
792 * register size to configure things far enough to be able to properly read
793 * the revision register.
795 static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
797 if (resource_size(res) == 8)
798 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
802 * sysc_parse_one - parses the interconnect target module registers
803 * @ddata: device driver data
804 * @reg: register to parse
806 static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
808 struct resource *res;
815 name = reg_names[reg];
821 res = platform_get_resource_byname(to_platform_device(ddata->dev),
822 IORESOURCE_MEM, name);
824 ddata->offsets[reg] = -ENODEV;
829 ddata->offsets[reg] = res->start - ddata->module_pa;
830 if (reg == SYSC_REVISION)
831 sysc_check_quirk_16bit(ddata, res);
836 static int sysc_parse_registers(struct sysc *ddata)
840 for (i = 0; i < SYSC_MAX_REGS; i++) {
841 error = sysc_parse_one(ddata, i);
850 * sysc_check_registers - check for misconfigured register overlaps
851 * @ddata: device driver data
853 static int sysc_check_registers(struct sysc *ddata)
855 int i, j, nr_regs = 0, nr_matches = 0;
857 for (i = 0; i < SYSC_MAX_REGS; i++) {
858 if (ddata->offsets[i] < 0)
861 if (ddata->offsets[i] > (ddata->module_size - 4)) {
862 dev_err(ddata->dev, "register outside module range");
867 for (j = 0; j < SYSC_MAX_REGS; j++) {
868 if (ddata->offsets[j] < 0)
871 if (ddata->offsets[i] == ddata->offsets[j])
877 if (nr_matches > nr_regs) {
878 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
879 nr_regs, nr_matches);
888 * sysc_ioremap - ioremap register space for the interconnect target module
889 * @ddata: device driver data
891 * Note that the interconnect target module registers can be anywhere
892 * within the interconnect target module range. For example, SGX has
893 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
894 * has them at offset 0x1200 in the CPSW_WR child. Usually the
895 * interconnect target module registers are at the beginning of
896 * the module range though.
898 static int sysc_ioremap(struct sysc *ddata)
902 if (ddata->offsets[SYSC_REVISION] < 0 &&
903 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
904 ddata->offsets[SYSC_SYSSTATUS] < 0) {
905 size = ddata->module_size;
907 size = max3(ddata->offsets[SYSC_REVISION],
908 ddata->offsets[SYSC_SYSCONFIG],
909 ddata->offsets[SYSC_SYSSTATUS]);
914 if ((size + sizeof(u32)) > ddata->module_size)
915 size = ddata->module_size;
918 ddata->module_va = devm_ioremap(ddata->dev,
921 if (!ddata->module_va)
928 * sysc_map_and_check_registers - ioremap and check device registers
929 * @ddata: device driver data
931 static int sysc_map_and_check_registers(struct sysc *ddata)
933 struct device_node *np = ddata->dev->of_node;
936 error = sysc_parse_and_check_child_range(ddata);
940 error = sysc_defer_non_critical(ddata);
944 sysc_check_children(ddata);
946 if (!of_property_present(np, "reg"))
949 error = sysc_parse_registers(ddata);
953 error = sysc_ioremap(ddata);
957 error = sysc_check_registers(ddata);
965 * sysc_show_rev - read and show interconnect target module revision
966 * @bufp: buffer to print the information to
967 * @ddata: device driver data
969 static int sysc_show_rev(char *bufp, struct sysc *ddata)
973 if (ddata->offsets[SYSC_REVISION] < 0)
974 return sprintf(bufp, ":NA");
976 len = sprintf(bufp, ":%08x", ddata->revision);
981 static int sysc_show_reg(struct sysc *ddata,
982 char *bufp, enum sysc_registers reg)
984 if (ddata->offsets[reg] < 0)
985 return sprintf(bufp, ":NA");
987 return sprintf(bufp, ":%x", ddata->offsets[reg]);
990 static int sysc_show_name(char *bufp, struct sysc *ddata)
995 return sprintf(bufp, ":%s", ddata->name);
999 * sysc_show_registers - show information about interconnect target module
1000 * @ddata: device driver data
1002 static void sysc_show_registers(struct sysc *ddata)
1008 for (i = 0; i < SYSC_MAX_REGS; i++)
1009 bufp += sysc_show_reg(ddata, bufp, i);
1011 bufp += sysc_show_rev(bufp, ddata);
1012 bufp += sysc_show_name(bufp, ddata);
1014 dev_dbg(ddata->dev, "%llx:%x%s\n",
1015 ddata->module_pa, ddata->module_size,
1020 * sysc_write_sysconfig - handle sysconfig quirks for register write
1021 * @ddata: device driver data
1022 * @value: register value
1024 static void sysc_write_sysconfig(struct sysc *ddata, u32 value)
1026 if (ddata->module_unlock_quirk)
1027 ddata->module_unlock_quirk(ddata);
1029 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], value);
1031 if (ddata->module_lock_quirk)
1032 ddata->module_lock_quirk(ddata);
1035 #define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
1036 #define SYSC_CLOCACT_ICK 2
1038 /* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
1039 static int sysc_enable_module(struct device *dev)
1042 const struct sysc_regbits *regbits;
1043 u32 reg, idlemodes, best_mode;
1046 ddata = dev_get_drvdata(dev);
1049 * Some modules like DSS reset automatically on idle. Enable optional
1050 * reset clocks and wait for OCP softreset to complete.
1052 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET) {
1053 error = sysc_enable_opt_clocks(ddata);
1056 "Optional clocks failed for enable: %i\n",
1062 * Some modules like i2c and hdq1w have unusable reset status unless
1063 * the module reset quirk is enabled. Skip status check on enable.
1065 if (!(ddata->cfg.quirks & SYSC_MODULE_QUIRK_ENA_RESETDONE)) {
1066 error = sysc_wait_softreset(ddata);
1068 dev_warn(ddata->dev, "OCP softreset timed out\n");
1070 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET)
1071 sysc_disable_opt_clocks(ddata);
1074 * Some subsystem private interconnects, like DSS top level module,
1075 * need only the automatic OCP softreset handling with no sysconfig
1076 * register bits to configure.
1078 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1081 regbits = ddata->cap->regbits;
1082 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1085 * Set CLOCKACTIVITY, we only use it for ick. And we only configure it
1086 * based on the SYSC_QUIRK_USE_CLOCKACT flag, not based on the hardware
1087 * capabilities. See the old HWMOD_SET_DEFAULT_CLOCKACT flag.
1089 if (regbits->clkact_shift >= 0 &&
1090 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT))
1091 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
1093 /* Set SIDLE mode */
1094 idlemodes = ddata->cfg.sidlemodes;
1095 if (!idlemodes || regbits->sidle_shift < 0)
1098 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
1099 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
1100 best_mode = SYSC_IDLE_NO;
1103 if (regbits->enwkup_shift >= 0 &&
1104 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
1105 reg &= ~BIT(regbits->enwkup_shift);
1107 best_mode = fls(ddata->cfg.sidlemodes) - 1;
1108 if (best_mode > SYSC_IDLE_MASK) {
1109 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1114 if (regbits->enwkup_shift >= 0 &&
1115 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
1116 reg |= BIT(regbits->enwkup_shift);
1119 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1120 reg |= best_mode << regbits->sidle_shift;
1121 sysc_write_sysconfig(ddata, reg);
1124 /* Set MIDLE mode */
1125 idlemodes = ddata->cfg.midlemodes;
1126 if (!idlemodes || regbits->midle_shift < 0)
1129 best_mode = fls(ddata->cfg.midlemodes) - 1;
1130 if (best_mode > SYSC_IDLE_MASK) {
1131 dev_err(dev, "%s: invalid midlemode\n", __func__);
1136 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_MSTANDBY)
1137 best_mode = SYSC_IDLE_NO;
1139 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1140 reg |= best_mode << regbits->midle_shift;
1141 sysc_write_sysconfig(ddata, reg);
1144 /* Autoidle bit must enabled separately if available */
1145 if (regbits->autoidle_shift >= 0 &&
1146 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
1147 reg |= 1 << regbits->autoidle_shift;
1148 sysc_write_sysconfig(ddata, reg);
1154 /* Save context and flush posted write */
1155 ddata->sysconfig = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1157 if (ddata->module_enable_quirk)
1158 ddata->module_enable_quirk(ddata);
1163 static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
1165 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
1166 *best_mode = SYSC_IDLE_SMART_WKUP;
1167 else if (idlemodes & BIT(SYSC_IDLE_SMART))
1168 *best_mode = SYSC_IDLE_SMART;
1169 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
1170 *best_mode = SYSC_IDLE_FORCE;
1177 /* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
1178 static int sysc_disable_module(struct device *dev)
1181 const struct sysc_regbits *regbits;
1182 u32 reg, idlemodes, best_mode;
1185 ddata = dev_get_drvdata(dev);
1186 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1189 if (ddata->module_disable_quirk)
1190 ddata->module_disable_quirk(ddata);
1192 regbits = ddata->cap->regbits;
1193 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1195 /* Set MIDLE mode */
1196 idlemodes = ddata->cfg.midlemodes;
1197 if (!idlemodes || regbits->midle_shift < 0)
1200 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1202 dev_err(dev, "%s: invalid midlemode\n", __func__);
1206 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_MSTANDBY) ||
1207 ddata->cfg.quirks & (SYSC_QUIRK_FORCE_MSTANDBY))
1208 best_mode = SYSC_IDLE_FORCE;
1210 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1211 reg |= best_mode << regbits->midle_shift;
1212 sysc_write_sysconfig(ddata, reg);
1215 /* Set SIDLE mode */
1216 idlemodes = ddata->cfg.sidlemodes;
1217 if (!idlemodes || regbits->sidle_shift < 0) {
1222 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
1223 best_mode = SYSC_IDLE_FORCE;
1225 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1227 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1233 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE_ACT) {
1235 if (regbits->enwkup_shift >= 0 &&
1236 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
1237 reg |= BIT(regbits->enwkup_shift);
1240 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1241 reg |= best_mode << regbits->sidle_shift;
1242 if (regbits->autoidle_shift >= 0 &&
1243 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1244 reg |= 1 << regbits->autoidle_shift;
1245 sysc_write_sysconfig(ddata, reg);
1250 /* Save context and flush posted write */
1251 ddata->sysconfig = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1256 static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1259 struct ti_sysc_platform_data *pdata;
1262 pdata = dev_get_platdata(ddata->dev);
1266 if (!pdata->idle_module)
1269 error = pdata->idle_module(dev, &ddata->cookie);
1271 dev_err(dev, "%s: could not idle: %i\n",
1274 reset_control_assert(ddata->rsts);
1279 static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1282 struct ti_sysc_platform_data *pdata;
1285 pdata = dev_get_platdata(ddata->dev);
1289 if (!pdata->enable_module)
1292 error = pdata->enable_module(dev, &ddata->cookie);
1294 dev_err(dev, "%s: could not enable: %i\n",
1297 reset_control_deassert(ddata->rsts);
1302 static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1307 ddata = dev_get_drvdata(dev);
1309 if (!ddata->enabled)
1312 sysc_clkdm_deny_idle(ddata);
1314 if (ddata->legacy_mode) {
1315 error = sysc_runtime_suspend_legacy(dev, ddata);
1317 goto err_allow_idle;
1319 error = sysc_disable_module(dev);
1321 goto err_allow_idle;
1324 sysc_disable_main_clocks(ddata);
1326 if (sysc_opt_clks_needed(ddata))
1327 sysc_disable_opt_clocks(ddata);
1329 ddata->enabled = false;
1332 sysc_clkdm_allow_idle(ddata);
1334 reset_control_assert(ddata->rsts);
1339 static int __maybe_unused sysc_runtime_resume(struct device *dev)
1344 ddata = dev_get_drvdata(dev);
1350 sysc_clkdm_deny_idle(ddata);
1352 if (sysc_opt_clks_needed(ddata)) {
1353 error = sysc_enable_opt_clocks(ddata);
1355 goto err_allow_idle;
1358 error = sysc_enable_main_clocks(ddata);
1360 goto err_opt_clocks;
1362 reset_control_deassert(ddata->rsts);
1364 if (ddata->legacy_mode) {
1365 error = sysc_runtime_resume_legacy(dev, ddata);
1367 goto err_main_clocks;
1369 error = sysc_enable_module(dev);
1371 goto err_main_clocks;
1374 ddata->enabled = true;
1376 sysc_clkdm_allow_idle(ddata);
1381 sysc_disable_main_clocks(ddata);
1383 if (sysc_opt_clks_needed(ddata))
1384 sysc_disable_opt_clocks(ddata);
1386 sysc_clkdm_allow_idle(ddata);
1392 * Checks if device context was lost. Assumes the sysconfig register value
1393 * after lost context is different from the configured value. Only works for
1396 * Eventually we may want to also add support to using the context lost
1397 * registers that some SoCs have.
1399 static int sysc_check_context(struct sysc *ddata)
1403 if (!ddata->enabled)
1406 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1407 if (reg == ddata->sysconfig)
1413 static int sysc_reinit_module(struct sysc *ddata, bool leave_enabled)
1415 struct device *dev = ddata->dev;
1418 if (ddata->enabled) {
1419 /* Nothing to do if enabled and context not lost */
1420 error = sysc_check_context(ddata);
1424 /* Disable target module if it is enabled */
1425 error = sysc_runtime_suspend(dev);
1427 dev_warn(dev, "reinit suspend failed: %i\n", error);
1430 /* Enable target module */
1431 error = sysc_runtime_resume(dev);
1433 dev_warn(dev, "reinit resume failed: %i\n", error);
1435 /* Some modules like am335x gpmc need reset and restore of sysconfig */
1436 if (ddata->cfg.quirks & SYSC_QUIRK_RESET_ON_CTX_LOST) {
1437 error = sysc_reset(ddata);
1439 dev_warn(dev, "reinit reset failed: %i\n", error);
1441 sysc_write_sysconfig(ddata, ddata->sysconfig);
1447 /* Disable target module if no leave_enabled was set */
1448 error = sysc_runtime_suspend(dev);
1450 dev_warn(dev, "reinit suspend failed: %i\n", error);
1455 static int __maybe_unused sysc_noirq_suspend(struct device *dev)
1459 ddata = dev_get_drvdata(dev);
1461 if (ddata->cfg.quirks &
1462 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
1465 if (!ddata->enabled)
1468 ddata->needs_resume = 1;
1470 return sysc_runtime_suspend(dev);
1473 static int __maybe_unused sysc_noirq_resume(struct device *dev)
1478 ddata = dev_get_drvdata(dev);
1480 if (ddata->cfg.quirks &
1481 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
1484 if (ddata->cfg.quirks & SYSC_QUIRK_REINIT_ON_RESUME) {
1485 error = sysc_reinit_module(ddata, ddata->needs_resume);
1487 dev_warn(dev, "noirq_resume failed: %i\n", error);
1488 } else if (ddata->needs_resume) {
1489 error = sysc_runtime_resume(dev);
1491 dev_warn(dev, "noirq_resume failed: %i\n", error);
1494 ddata->needs_resume = 0;
1499 static const struct dev_pm_ops sysc_pm_ops = {
1500 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
1501 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1502 sysc_runtime_resume,
1506 /* Module revision register based quirks */
1507 struct sysc_revision_quirk {
1518 #define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1519 optrev_val, optrevmask, optquirkmask) \
1521 .name = (optname), \
1522 .base = (optbase), \
1523 .rev_offset = (optrev), \
1524 .sysc_offset = (optsysc), \
1525 .syss_offset = (optsyss), \
1526 .revision = (optrev_val), \
1527 .revision_mask = (optrevmask), \
1528 .quirks = (optquirkmask), \
1531 static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1532 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
1533 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1534 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
1535 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
1536 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
1537 /* Uarts on omap4 and later */
1538 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
1539 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
1540 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
1541 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
1542 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47424e03, 0xffffffff,
1543 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
1545 /* Quirks that need to be set based on the module address */
1546 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -ENODEV, 0x50000800, 0xffffffff,
1547 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1548 SYSC_QUIRK_SWSUP_SIDLE),
1550 /* Quirks that need to be set based on detected module */
1551 SYSC_QUIRK("aess", 0, 0, 0x10, -ENODEV, 0x40000000, 0xffffffff,
1552 SYSC_MODULE_QUIRK_AESS),
1553 /* Errata i893 handling for dra7 dcan1 and 2 */
1554 SYSC_QUIRK("dcan", 0x4ae3c000, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff,
1555 SYSC_QUIRK_CLKDM_NOAUTO),
1556 SYSC_QUIRK("dcan", 0x48480000, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff,
1557 SYSC_QUIRK_CLKDM_NOAUTO),
1558 SYSC_QUIRK("dss", 0x4832a000, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
1559 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
1560 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000040, 0xffffffff,
1561 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
1562 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000061, 0xffffffff,
1563 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
1564 SYSC_QUIRK("dwc3", 0x48880000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
1565 SYSC_QUIRK_CLKDM_NOAUTO),
1566 SYSC_QUIRK("dwc3", 0x488c0000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
1567 SYSC_QUIRK_CLKDM_NOAUTO),
1568 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
1569 SYSC_QUIRK_OPT_CLKS_IN_RESET),
1570 SYSC_QUIRK("gpmc", 0, 0, 0x10, 0x14, 0x00000060, 0xffffffff,
1571 SYSC_QUIRK_REINIT_ON_CTX_LOST | SYSC_QUIRK_RESET_ON_CTX_LOST |
1572 SYSC_QUIRK_GPMC_DEBUG),
1573 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50030200, 0xffffffff,
1574 SYSC_QUIRK_OPT_CLKS_NEEDED),
1575 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
1576 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
1577 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
1578 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
1579 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
1580 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
1581 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
1582 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
1583 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
1584 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
1585 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
1586 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
1587 SYSC_QUIRK("gpu", 0x50000000, 0x14, -ENODEV, -ENODEV, 0x00010201, 0xffffffff, 0),
1588 SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff,
1589 SYSC_MODULE_QUIRK_SGX),
1590 SYSC_QUIRK("lcdc", 0, 0, 0x54, -ENODEV, 0x4f201000, 0xffffffff,
1591 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1592 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44306302, 0xffffffff,
1593 SYSC_QUIRK_SWSUP_SIDLE),
1594 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -ENODEV, 0x4eb01908, 0xffff00f0,
1595 SYSC_MODULE_QUIRK_RTC_UNLOCK),
1596 SYSC_QUIRK("tptc", 0, 0, 0x10, -ENODEV, 0x40006c00, 0xffffefff,
1597 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1598 SYSC_QUIRK("tptc", 0, 0, -ENODEV, -ENODEV, 0x40007c00, 0xffffffff,
1599 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1600 SYSC_QUIRK("sata", 0, 0xfc, 0x1100, -ENODEV, 0x5e412000, 0xffffffff,
1601 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1602 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff,
1603 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1604 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -ENODEV, 0x50700101, 0xffffffff,
1605 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1606 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000033,
1607 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
1608 SYSC_MODULE_QUIRK_OTG),
1609 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000040,
1610 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
1611 SYSC_MODULE_QUIRK_OTG),
1612 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1613 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
1614 SYSC_MODULE_QUIRK_OTG),
1615 SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -ENODEV, 0x4ea2080d, 0xffffffff,
1616 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
1617 SYSC_QUIRK_REINIT_ON_CTX_LOST),
1618 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1619 SYSC_MODULE_QUIRK_WDT),
1620 /* PRUSS on am3, am4 and am5 */
1621 SYSC_QUIRK("pruss", 0, 0x26000, 0x26004, -ENODEV, 0x47000000, 0xff000000,
1622 SYSC_MODULE_QUIRK_PRUSS),
1623 /* Watchdog on am3 and am4 */
1624 SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1625 SYSC_MODULE_QUIRK_WDT | SYSC_QUIRK_SWSUP_SIDLE),
1628 SYSC_QUIRK("adc", 0, 0, 0x10, -ENODEV, 0x47300001, 0xffffffff, 0),
1629 SYSC_QUIRK("atl", 0, 0, -ENODEV, -ENODEV, 0x0a070100, 0xffffffff, 0),
1630 SYSC_QUIRK("cm", 0, 0, -ENODEV, -ENODEV, 0x40000301, 0xffffffff, 0),
1631 SYSC_QUIRK("control", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
1632 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
1634 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff, 0),
1635 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0x4edb1902, 0xffffffff, 0),
1636 SYSC_QUIRK("dispc", 0x4832a400, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1637 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1638 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000051, 0xffffffff, 0),
1639 SYSC_QUIRK("dmic", 0, 0, 0x10, -ENODEV, 0x50010000, 0xffffffff, 0),
1640 SYSC_QUIRK("dsi", 0x58004000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1641 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1642 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1643 SYSC_QUIRK("dsi", 0x58009000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1644 SYSC_QUIRK("dwc3", 0, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, 0),
1645 SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1646 SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1647 SYSC_QUIRK("elm", 0x48080000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
1648 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x40441403, 0xffff0fff, 0),
1649 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x50440500, 0xffffffff, 0),
1650 SYSC_QUIRK("epwmss", 0, 0, 0x4, -ENODEV, 0x47400001, 0xffffffff, 0),
1651 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -ENODEV, 0, 0, 0),
1652 SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff, 0),
1653 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50031d00, 0xffffffff, 0),
1654 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
1655 SYSC_QUIRK("iss", 0, 0, 0x10, -ENODEV, 0x40000101, 0xffffffff, 0),
1656 SYSC_QUIRK("keypad", 0x4a31c000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
1657 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44307b02, 0xffffffff, 0),
1658 SYSC_QUIRK("mcbsp", 0, -ENODEV, 0x8c, -ENODEV, 0, 0, 0),
1659 SYSC_QUIRK("mcspi", 0, 0, 0x10, -ENODEV, 0x40300a0b, 0xffff00ff, 0),
1660 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
1661 SYSC_QUIRK("mailbox", 0, 0, 0x10, -ENODEV, 0x00000400, 0xffffffff, 0),
1662 SYSC_QUIRK("m3", 0, 0, -ENODEV, -ENODEV, 0x5f580105, 0x0fff0f00, 0),
1663 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
1664 SYSC_QUIRK("ocp2scp", 0, 0, -ENODEV, -ENODEV, 0x50060007, 0xffffffff, 0),
1665 SYSC_QUIRK("padconf", 0, 0, 0x10, -ENODEV, 0x4fff0800, 0xffffffff, 0),
1666 SYSC_QUIRK("padconf", 0, 0, -ENODEV, -ENODEV, 0x40001100, 0xffffffff, 0),
1667 SYSC_QUIRK("pcie", 0x51000000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
1668 SYSC_QUIRK("pcie", 0x51800000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
1669 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000100, 0xffffffff, 0),
1670 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x00004102, 0xffffffff, 0),
1671 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000400, 0xffffffff, 0),
1672 SYSC_QUIRK("rfbi", 0x4832a800, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1673 SYSC_QUIRK("rfbi", 0x58002000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1674 SYSC_QUIRK("scm", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
1675 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4e8b0100, 0xffffffff, 0),
1676 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4f000100, 0xffffffff, 0),
1677 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x40000900, 0xffffffff, 0),
1678 SYSC_QUIRK("scrm", 0, 0, -ENODEV, -ENODEV, 0x00000010, 0xffffffff, 0),
1679 SYSC_QUIRK("sdio", 0, 0, 0x10, -ENODEV, 0x40202301, 0xffff0ff0, 0),
1680 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
1681 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
1682 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff, 0),
1683 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40000902, 0xffffffff, 0),
1684 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40002903, 0xffffffff, 0),
1685 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x24, -ENODEV, 0x00000000, 0xffffffff, 0),
1686 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x38, -ENODEV, 0x00000000, 0xffffffff, 0),
1687 SYSC_QUIRK("spinlock", 0, 0, 0x10, -ENODEV, 0x50020000, 0xffffffff, 0),
1688 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -ENODEV, 0x00000020, 0xffffffff, 0),
1689 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000013, 0xffffffff, 0),
1690 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff, 0),
1691 /* Some timers on omap4 and later */
1692 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x50002100, 0xffffffff, 0),
1693 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x4fff1301, 0xffff00ff, 0),
1694 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000040, 0xffffffff, 0),
1695 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000011, 0xffffffff, 0),
1696 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000060, 0xffffffff, 0),
1697 SYSC_QUIRK("tpcc", 0, 0, -ENODEV, -ENODEV, 0x40014c00, 0xffffffff, 0),
1698 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
1699 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
1700 SYSC_QUIRK("venc", 0x58003000, 0, -ENODEV, -ENODEV, 0x00000002, 0xffffffff, 0),
1701 SYSC_QUIRK("vfpe", 0, 0, 0x104, -ENODEV, 0x4d001200, 0xffffffff, 0),
1706 * Early quirks based on module base and register offsets only that are
1707 * needed before the module revision can be read
1709 static void sysc_init_early_quirks(struct sysc *ddata)
1711 const struct sysc_revision_quirk *q;
1714 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1715 q = &sysc_revision_quirks[i];
1720 if (q->base != ddata->module_pa)
1723 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
1726 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1729 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1732 ddata->name = q->name;
1733 ddata->cfg.quirks |= q->quirks;
1737 /* Quirks that also consider the revision register value */
1738 static void sysc_init_revision_quirks(struct sysc *ddata)
1740 const struct sysc_revision_quirk *q;
1743 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1744 q = &sysc_revision_quirks[i];
1746 if (q->base && q->base != ddata->module_pa)
1749 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
1752 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1755 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1758 if (q->revision == ddata->revision ||
1759 (q->revision & q->revision_mask) ==
1760 (ddata->revision & q->revision_mask)) {
1761 ddata->name = q->name;
1762 ddata->cfg.quirks |= q->quirks;
1768 * DSS needs dispc outputs disabled to reset modules. Returns mask of
1769 * enabled DSS interrupts. Eventually we may be able to do this on
1770 * dispc init rather than top-level DSS init.
1772 static u32 sysc_quirk_dispc(struct sysc *ddata, int dispc_offset,
1775 bool lcd_en, digit_en, lcd2_en = false, lcd3_en = false;
1776 const int lcd_en_mask = BIT(0), digit_en_mask = BIT(1);
1778 bool framedonetv_irq = true;
1779 u32 val, irq_mask = 0;
1781 switch (sysc_soc->soc) {
1782 case SOC_2420 ... SOC_3630:
1784 framedonetv_irq = false;
1786 case SOC_4430 ... SOC_4470:
1795 framedonetv_irq = false;
1802 /* Remap the whole module range to be able to reset dispc outputs */
1803 devm_iounmap(ddata->dev, ddata->module_va);
1804 ddata->module_va = devm_ioremap(ddata->dev,
1806 ddata->module_size);
1807 if (!ddata->module_va)
1810 /* DISP_CONTROL, shut down lcd and digit on disable if enabled */
1811 val = sysc_read(ddata, dispc_offset + 0x40);
1812 lcd_en = val & lcd_en_mask;
1813 digit_en = val & digit_en_mask;
1815 irq_mask |= BIT(0); /* FRAMEDONE */
1817 if (framedonetv_irq)
1818 irq_mask |= BIT(24); /* FRAMEDONETV */
1820 irq_mask |= BIT(2) | BIT(3); /* EVSYNC bits */
1822 if (disable && (lcd_en || digit_en))
1823 sysc_write(ddata, dispc_offset + 0x40,
1824 val & ~(lcd_en_mask | digit_en_mask));
1826 if (manager_count <= 2)
1829 /* DISPC_CONTROL2 */
1830 val = sysc_read(ddata, dispc_offset + 0x238);
1831 lcd2_en = val & lcd_en_mask;
1833 irq_mask |= BIT(22); /* FRAMEDONE2 */
1834 if (disable && lcd2_en)
1835 sysc_write(ddata, dispc_offset + 0x238,
1836 val & ~lcd_en_mask);
1838 if (manager_count <= 3)
1841 /* DISPC_CONTROL3 */
1842 val = sysc_read(ddata, dispc_offset + 0x848);
1843 lcd3_en = val & lcd_en_mask;
1845 irq_mask |= BIT(30); /* FRAMEDONE3 */
1846 if (disable && lcd3_en)
1847 sysc_write(ddata, dispc_offset + 0x848,
1848 val & ~lcd_en_mask);
1853 /* DSS needs child outputs disabled and SDI registers cleared for reset */
1854 static void sysc_pre_reset_quirk_dss(struct sysc *ddata)
1856 const int dispc_offset = 0x1000;
1860 /* Get enabled outputs */
1861 irq_mask = sysc_quirk_dispc(ddata, dispc_offset, false);
1865 /* Clear IRQSTATUS */
1866 sysc_write(ddata, dispc_offset + 0x18, irq_mask);
1868 /* Disable outputs */
1869 val = sysc_quirk_dispc(ddata, dispc_offset, true);
1871 /* Poll IRQSTATUS */
1872 error = readl_poll_timeout(ddata->module_va + dispc_offset + 0x18,
1873 val, val != irq_mask, 100, 50);
1875 dev_warn(ddata->dev, "%s: timed out %08x !+ %08x\n",
1876 __func__, val, irq_mask);
1878 if (sysc_soc->soc == SOC_3430 || sysc_soc->soc == SOC_AM35) {
1879 /* Clear DSS_SDI_CONTROL */
1880 sysc_write(ddata, 0x44, 0);
1882 /* Clear DSS_PLL_CONTROL */
1883 sysc_write(ddata, 0x48, 0);
1886 /* Clear DSS_CONTROL to switch DSS clock sources to PRCM if not */
1887 sysc_write(ddata, 0x40, 0);
1890 /* 1-wire needs module's internal clocks enabled for reset */
1891 static void sysc_pre_reset_quirk_hdq1w(struct sysc *ddata)
1893 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1896 val = sysc_read(ddata, offset);
1898 sysc_write(ddata, offset, val);
1901 /* AESS (Audio Engine SubSystem) needs autogating set after enable */
1902 static void sysc_module_enable_quirk_aess(struct sysc *ddata)
1904 int offset = 0x7c; /* AESS_AUTO_GATING_ENABLE */
1906 sysc_write(ddata, offset, 1);
1909 /* I2C needs to be disabled for reset */
1910 static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1915 /* I2C_CON, omap2/3 is different from omap4 and later */
1916 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1922 val = sysc_read(ddata, offset);
1927 sysc_write(ddata, offset, val);
1930 static void sysc_pre_reset_quirk_i2c(struct sysc *ddata)
1932 sysc_clk_quirk_i2c(ddata, false);
1935 static void sysc_post_reset_quirk_i2c(struct sysc *ddata)
1937 sysc_clk_quirk_i2c(ddata, true);
1940 /* RTC on am3 and 4 needs to be unlocked and locked for sysconfig */
1941 static void sysc_quirk_rtc(struct sysc *ddata, bool lock)
1943 u32 val, kick0_val = 0, kick1_val = 0;
1944 unsigned long flags;
1948 kick0_val = 0x83e70b13;
1949 kick1_val = 0x95a4f1e0;
1952 local_irq_save(flags);
1953 /* RTC_STATUS BUSY bit may stay active for 1/32768 seconds (~30 usec) */
1954 error = readl_poll_timeout_atomic(ddata->module_va + 0x44, val,
1955 !(val & BIT(0)), 100, 50);
1957 dev_warn(ddata->dev, "rtc busy timeout\n");
1958 /* Now we have ~15 microseconds to read/write various registers */
1959 sysc_write(ddata, 0x6c, kick0_val);
1960 sysc_write(ddata, 0x70, kick1_val);
1961 local_irq_restore(flags);
1964 static void sysc_module_unlock_quirk_rtc(struct sysc *ddata)
1966 sysc_quirk_rtc(ddata, false);
1969 static void sysc_module_lock_quirk_rtc(struct sysc *ddata)
1971 sysc_quirk_rtc(ddata, true);
1974 /* OTG omap2430 glue layer up to omap4 needs OTG_FORCESTDBY configured */
1975 static void sysc_module_enable_quirk_otg(struct sysc *ddata)
1977 int offset = 0x414; /* OTG_FORCESTDBY */
1979 sysc_write(ddata, offset, 0);
1982 static void sysc_module_disable_quirk_otg(struct sysc *ddata)
1984 int offset = 0x414; /* OTG_FORCESTDBY */
1985 u32 val = BIT(0); /* ENABLEFORCE */
1987 sysc_write(ddata, offset, val);
1990 /* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */
1991 static void sysc_module_enable_quirk_sgx(struct sysc *ddata)
1993 int offset = 0xff08; /* OCP_DEBUG_CONFIG */
1994 u32 val = BIT(31); /* THALIA_INT_BYPASS */
1996 sysc_write(ddata, offset, val);
1999 /* Watchdog timer needs a disable sequence after reset */
2000 static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
2002 int wps, spr, error;
2008 sysc_write(ddata, spr, 0xaaaa);
2009 error = readl_poll_timeout(ddata->module_va + wps, val,
2011 MAX_MODULE_SOFTRESET_WAIT);
2013 dev_warn(ddata->dev, "wdt disable step1 failed\n");
2015 sysc_write(ddata, spr, 0x5555);
2016 error = readl_poll_timeout(ddata->module_va + wps, val,
2018 MAX_MODULE_SOFTRESET_WAIT);
2020 dev_warn(ddata->dev, "wdt disable step2 failed\n");
2023 /* PRUSS needs to set MSTANDBY_INIT inorder to idle properly */
2024 static void sysc_module_disable_quirk_pruss(struct sysc *ddata)
2028 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
2029 reg |= SYSC_PRUSS_STANDBY_INIT;
2030 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
2033 static void sysc_init_module_quirks(struct sysc *ddata)
2035 if (ddata->legacy_mode || !ddata->name)
2038 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
2039 ddata->pre_reset_quirk = sysc_pre_reset_quirk_hdq1w;
2044 #ifdef CONFIG_OMAP_GPMC_DEBUG
2045 if (ddata->cfg.quirks & SYSC_QUIRK_GPMC_DEBUG) {
2046 ddata->cfg.quirks |= SYSC_QUIRK_NO_RESET_ON_INIT;
2052 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
2053 ddata->pre_reset_quirk = sysc_pre_reset_quirk_i2c;
2054 ddata->post_reset_quirk = sysc_post_reset_quirk_i2c;
2059 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_AESS)
2060 ddata->module_enable_quirk = sysc_module_enable_quirk_aess;
2062 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_DSS_RESET)
2063 ddata->pre_reset_quirk = sysc_pre_reset_quirk_dss;
2065 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_RTC_UNLOCK) {
2066 ddata->module_unlock_quirk = sysc_module_unlock_quirk_rtc;
2067 ddata->module_lock_quirk = sysc_module_lock_quirk_rtc;
2072 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_OTG) {
2073 ddata->module_enable_quirk = sysc_module_enable_quirk_otg;
2074 ddata->module_disable_quirk = sysc_module_disable_quirk_otg;
2077 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_SGX)
2078 ddata->module_enable_quirk = sysc_module_enable_quirk_sgx;
2080 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT) {
2081 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
2082 ddata->module_disable_quirk = sysc_reset_done_quirk_wdt;
2085 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_PRUSS)
2086 ddata->module_disable_quirk = sysc_module_disable_quirk_pruss;
2089 static int sysc_clockdomain_init(struct sysc *ddata)
2091 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2092 struct clk *fck = NULL, *ick = NULL;
2095 if (!pdata || !pdata->init_clockdomain)
2098 switch (ddata->nr_clocks) {
2100 ick = ddata->clocks[SYSC_ICK];
2103 fck = ddata->clocks[SYSC_FCK];
2109 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
2110 if (!error || error == -ENODEV)
2117 * Note that pdata->init_module() typically does a reset first. After
2118 * pdata->init_module() is done, PM runtime can be used for the interconnect
2121 static int sysc_legacy_init(struct sysc *ddata)
2123 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2126 if (!pdata || !pdata->init_module)
2129 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
2130 if (error == -EEXIST)
2137 * Note that the caller must ensure the interconnect target module is enabled
2138 * before calling reset. Otherwise reset will not complete.
2140 static int sysc_reset(struct sysc *ddata)
2142 int sysc_offset, sysc_val, error;
2145 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
2147 if (ddata->legacy_mode ||
2148 ddata->cap->regbits->srst_shift < 0 ||
2149 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
2152 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
2154 if (ddata->pre_reset_quirk)
2155 ddata->pre_reset_quirk(ddata);
2157 if (sysc_offset >= 0) {
2158 sysc_val = sysc_read_sysconfig(ddata);
2159 sysc_val |= sysc_mask;
2160 sysc_write(ddata, sysc_offset, sysc_val);
2161 /* Flush posted write */
2162 sysc_val = sysc_read_sysconfig(ddata);
2165 if (ddata->cfg.srst_udelay)
2166 fsleep(ddata->cfg.srst_udelay);
2168 if (ddata->post_reset_quirk)
2169 ddata->post_reset_quirk(ddata);
2171 error = sysc_wait_softreset(ddata);
2173 dev_warn(ddata->dev, "OCP softreset timed out\n");
2175 if (ddata->reset_done_quirk)
2176 ddata->reset_done_quirk(ddata);
2182 * At this point the module is configured enough to read the revision but
2183 * module may not be completely configured yet to use PM runtime. Enable
2184 * all clocks directly during init to configure the quirks needed for PM
2185 * runtime based on the revision register.
2187 static int sysc_init_module(struct sysc *ddata)
2189 bool rstctrl_deasserted = false;
2192 error = sysc_clockdomain_init(ddata);
2196 sysc_clkdm_deny_idle(ddata);
2199 * Always enable clocks. The bootloader may or may not have enabled
2200 * the related clocks.
2202 error = sysc_enable_opt_clocks(ddata);
2206 error = sysc_enable_main_clocks(ddata);
2208 goto err_opt_clocks;
2210 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
2211 error = reset_control_deassert(ddata->rsts);
2213 goto err_main_clocks;
2214 rstctrl_deasserted = true;
2217 ddata->revision = sysc_read_revision(ddata);
2218 sysc_init_revision_quirks(ddata);
2219 sysc_init_module_quirks(ddata);
2221 if (ddata->legacy_mode) {
2222 error = sysc_legacy_init(ddata);
2224 goto err_main_clocks;
2227 if (!ddata->legacy_mode) {
2228 error = sysc_enable_module(ddata->dev);
2230 goto err_main_clocks;
2233 error = sysc_reset(ddata);
2235 dev_err(ddata->dev, "Reset failed with %d\n", error);
2237 if (error && !ddata->legacy_mode)
2238 sysc_disable_module(ddata->dev);
2242 sysc_disable_main_clocks(ddata);
2244 /* No re-enable of clockdomain autoidle to prevent module autoidle */
2246 sysc_disable_opt_clocks(ddata);
2247 sysc_clkdm_allow_idle(ddata);
2250 if (error && rstctrl_deasserted &&
2251 !(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
2252 reset_control_assert(ddata->rsts);
2257 static int sysc_init_sysc_mask(struct sysc *ddata)
2259 struct device_node *np = ddata->dev->of_node;
2263 error = of_property_read_u32(np, "ti,sysc-mask", &val);
2267 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
2272 static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
2275 struct device_node *np = ddata->dev->of_node;
2276 struct property *prop;
2280 of_property_for_each_u32(np, name, prop, p, val) {
2281 if (val >= SYSC_NR_IDLEMODES) {
2282 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
2285 *idlemodes |= (1 << val);
2291 static int sysc_init_idlemodes(struct sysc *ddata)
2295 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
2300 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
2309 * Only some devices on omap4 and later have SYSCONFIG reset done
2310 * bit. We can detect this if there is no SYSSTATUS at all, or the
2311 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
2312 * have multiple bits for the child devices like OHCI and EHCI.
2313 * Depends on SYSC being parsed first.
2315 static int sysc_init_syss_mask(struct sysc *ddata)
2317 struct device_node *np = ddata->dev->of_node;
2321 error = of_property_read_u32(np, "ti,syss-mask", &val);
2323 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
2324 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
2325 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2326 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2331 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2332 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2334 ddata->cfg.syss_mask = val;
2340 * Many child device drivers need to have fck and opt clocks available
2341 * to get the clock rate for device internal configuration etc.
2343 static int sysc_child_add_named_clock(struct sysc *ddata,
2344 struct device *child,
2348 struct clk_lookup *l;
2354 clk = clk_get(child, name);
2360 clk = clk_get(ddata->dev, name);
2364 l = clkdev_create(clk, name, dev_name(child));
2373 static int sysc_child_add_clocks(struct sysc *ddata,
2374 struct device *child)
2378 for (i = 0; i < ddata->nr_clocks; i++) {
2379 error = sysc_child_add_named_clock(ddata,
2381 ddata->clock_roles[i]);
2382 if (error && error != -EEXIST) {
2383 dev_err(ddata->dev, "could not add child clock %s: %i\n",
2384 ddata->clock_roles[i], error);
2393 static struct device_type sysc_device_type = {
2396 static struct sysc *sysc_child_to_parent(struct device *dev)
2398 struct device *parent = dev->parent;
2400 if (!parent || parent->type != &sysc_device_type)
2403 return dev_get_drvdata(parent);
2406 static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
2411 ddata = sysc_child_to_parent(dev);
2413 error = pm_generic_runtime_suspend(dev);
2417 if (!ddata->enabled)
2420 return sysc_runtime_suspend(ddata->dev);
2423 static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
2428 ddata = sysc_child_to_parent(dev);
2430 if (!ddata->enabled) {
2431 error = sysc_runtime_resume(ddata->dev);
2434 "%s error: %i\n", __func__, error);
2437 return pm_generic_runtime_resume(dev);
2440 #ifdef CONFIG_PM_SLEEP
2441 static int sysc_child_suspend_noirq(struct device *dev)
2446 ddata = sysc_child_to_parent(dev);
2448 dev_dbg(ddata->dev, "%s %s\n", __func__,
2449 ddata->name ? ddata->name : "");
2451 error = pm_generic_suspend_noirq(dev);
2453 dev_err(dev, "%s error at %i: %i\n",
2454 __func__, __LINE__, error);
2459 if (!pm_runtime_status_suspended(dev)) {
2460 error = pm_generic_runtime_suspend(dev);
2462 dev_dbg(dev, "%s busy at %i: %i\n",
2463 __func__, __LINE__, error);
2468 error = sysc_runtime_suspend(ddata->dev);
2470 dev_err(dev, "%s error at %i: %i\n",
2471 __func__, __LINE__, error);
2476 ddata->child_needs_resume = true;
2482 static int sysc_child_resume_noirq(struct device *dev)
2487 ddata = sysc_child_to_parent(dev);
2489 dev_dbg(ddata->dev, "%s %s\n", __func__,
2490 ddata->name ? ddata->name : "");
2492 if (ddata->child_needs_resume) {
2493 ddata->child_needs_resume = false;
2495 error = sysc_runtime_resume(ddata->dev);
2498 "%s runtime resume error: %i\n",
2501 error = pm_generic_runtime_resume(dev);
2504 "%s generic runtime resume: %i\n",
2508 return pm_generic_resume_noirq(dev);
2512 static struct dev_pm_domain sysc_child_pm_domain = {
2514 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
2515 sysc_child_runtime_resume,
2517 USE_PLATFORM_PM_SLEEP_OPS
2518 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
2519 sysc_child_resume_noirq)
2523 /* Caller needs to take list_lock if ever used outside of cpu_pm */
2524 static void sysc_reinit_modules(struct sysc_soc_info *soc)
2526 struct sysc_module *module;
2529 list_for_each_entry(module, &sysc_soc->restored_modules, node) {
2530 ddata = module->ddata;
2531 sysc_reinit_module(ddata, ddata->enabled);
2536 * sysc_context_notifier - optionally reset and restore module after idle
2537 * @nb: notifier block
2541 * Some interconnect target modules need to be restored, or reset and restored
2542 * on CPU_PM CPU_PM_CLUSTER_EXIT notifier. This is needed at least for am335x
2543 * OTG and GPMC target modules even if the modules are unused.
2545 static int sysc_context_notifier(struct notifier_block *nb, unsigned long cmd,
2548 struct sysc_soc_info *soc;
2550 soc = container_of(nb, struct sysc_soc_info, nb);
2553 case CPU_CLUSTER_PM_ENTER:
2555 case CPU_CLUSTER_PM_ENTER_FAILED: /* No need to restore context */
2557 case CPU_CLUSTER_PM_EXIT:
2558 sysc_reinit_modules(soc);
2566 * sysc_add_restored - optionally add reset and restore quirk hanlling
2567 * @ddata: device data
2569 static void sysc_add_restored(struct sysc *ddata)
2571 struct sysc_module *restored_module;
2573 restored_module = kzalloc(sizeof(*restored_module), GFP_KERNEL);
2574 if (!restored_module)
2577 restored_module->ddata = ddata;
2579 mutex_lock(&sysc_soc->list_lock);
2581 list_add(&restored_module->node, &sysc_soc->restored_modules);
2583 if (sysc_soc->nb.notifier_call)
2586 sysc_soc->nb.notifier_call = sysc_context_notifier;
2587 cpu_pm_register_notifier(&sysc_soc->nb);
2590 mutex_unlock(&sysc_soc->list_lock);
2594 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
2595 * @ddata: device driver data
2596 * @child: child device driver
2598 * Allow idle for child devices as done with _od_runtime_suspend().
2599 * Otherwise many child devices will not idle because of the permanent
2600 * parent usecount set in pm_runtime_irq_safe().
2602 * Note that the long term solution is to just modify the child device
2603 * drivers to not set pm_runtime_irq_safe() and then this can be just
2606 static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
2608 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
2609 dev_pm_domain_set(child, &sysc_child_pm_domain);
2612 static int sysc_notifier_call(struct notifier_block *nb,
2613 unsigned long event, void *device)
2615 struct device *dev = device;
2619 ddata = sysc_child_to_parent(dev);
2624 case BUS_NOTIFY_ADD_DEVICE:
2625 error = sysc_child_add_clocks(ddata, dev);
2628 sysc_legacy_idle_quirk(ddata, dev);
2637 static struct notifier_block sysc_nb = {
2638 .notifier_call = sysc_notifier_call,
2641 /* Device tree configured quirks */
2642 struct sysc_dts_quirk {
2647 static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2648 { .name = "ti,no-idle-on-init",
2649 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2650 { .name = "ti,no-reset-on-init",
2651 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
2652 { .name = "ti,no-idle",
2653 .mask = SYSC_QUIRK_NO_IDLE, },
2656 static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2659 const struct property *prop;
2662 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
2663 const char *name = sysc_dts_quirks[i].name;
2665 prop = of_get_property(np, name, &len);
2669 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
2671 dev_warn(ddata->dev,
2672 "dts flag should be at module level for %s\n",
2678 static int sysc_init_dts_quirks(struct sysc *ddata)
2680 struct device_node *np = ddata->dev->of_node;
2684 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2686 sysc_parse_dts_quirks(ddata, np, false);
2687 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2690 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2694 ddata->cfg.srst_udelay = (u8)val;
2700 static void sysc_unprepare(struct sysc *ddata)
2707 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2708 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2709 clk_unprepare(ddata->clocks[i]);
2714 * Common sysc register bits found on omap2, also known as type1
2716 static const struct sysc_regbits sysc_regbits_omap2 = {
2717 .dmadisable_shift = -ENODEV,
2724 .autoidle_shift = 0,
2727 static const struct sysc_capabilities sysc_omap2 = {
2728 .type = TI_SYSC_OMAP2,
2729 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2730 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2731 SYSC_OMAP2_AUTOIDLE,
2732 .regbits = &sysc_regbits_omap2,
2735 /* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2736 static const struct sysc_capabilities sysc_omap2_timer = {
2737 .type = TI_SYSC_OMAP2_TIMER,
2738 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2739 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2740 SYSC_OMAP2_AUTOIDLE,
2741 .regbits = &sysc_regbits_omap2,
2742 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2746 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2747 * with different sidle position
2749 static const struct sysc_regbits sysc_regbits_omap3_sham = {
2750 .dmadisable_shift = -ENODEV,
2751 .midle_shift = -ENODEV,
2753 .clkact_shift = -ENODEV,
2754 .enwkup_shift = -ENODEV,
2756 .autoidle_shift = 0,
2757 .emufree_shift = -ENODEV,
2760 static const struct sysc_capabilities sysc_omap3_sham = {
2761 .type = TI_SYSC_OMAP3_SHAM,
2762 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2763 .regbits = &sysc_regbits_omap3_sham,
2767 * AES register bits found on omap3 and later, a variant of
2768 * sysc_regbits_omap2 with different sidle position
2770 static const struct sysc_regbits sysc_regbits_omap3_aes = {
2771 .dmadisable_shift = -ENODEV,
2772 .midle_shift = -ENODEV,
2774 .clkact_shift = -ENODEV,
2775 .enwkup_shift = -ENODEV,
2777 .autoidle_shift = 0,
2778 .emufree_shift = -ENODEV,
2781 static const struct sysc_capabilities sysc_omap3_aes = {
2782 .type = TI_SYSC_OMAP3_AES,
2783 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2784 .regbits = &sysc_regbits_omap3_aes,
2788 * Common sysc register bits found on omap4, also known as type2
2790 static const struct sysc_regbits sysc_regbits_omap4 = {
2791 .dmadisable_shift = 16,
2794 .clkact_shift = -ENODEV,
2795 .enwkup_shift = -ENODEV,
2798 .autoidle_shift = -ENODEV,
2801 static const struct sysc_capabilities sysc_omap4 = {
2802 .type = TI_SYSC_OMAP4,
2803 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2804 SYSC_OMAP4_SOFTRESET,
2805 .regbits = &sysc_regbits_omap4,
2808 static const struct sysc_capabilities sysc_omap4_timer = {
2809 .type = TI_SYSC_OMAP4_TIMER,
2810 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2811 SYSC_OMAP4_SOFTRESET,
2812 .regbits = &sysc_regbits_omap4,
2816 * Common sysc register bits found on omap4, also known as type3
2818 static const struct sysc_regbits sysc_regbits_omap4_simple = {
2819 .dmadisable_shift = -ENODEV,
2822 .clkact_shift = -ENODEV,
2823 .enwkup_shift = -ENODEV,
2824 .srst_shift = -ENODEV,
2825 .emufree_shift = -ENODEV,
2826 .autoidle_shift = -ENODEV,
2829 static const struct sysc_capabilities sysc_omap4_simple = {
2830 .type = TI_SYSC_OMAP4_SIMPLE,
2831 .regbits = &sysc_regbits_omap4_simple,
2835 * SmartReflex sysc found on omap34xx
2837 static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2838 .dmadisable_shift = -ENODEV,
2839 .midle_shift = -ENODEV,
2840 .sidle_shift = -ENODEV,
2842 .enwkup_shift = -ENODEV,
2843 .srst_shift = -ENODEV,
2844 .emufree_shift = -ENODEV,
2845 .autoidle_shift = -ENODEV,
2848 static const struct sysc_capabilities sysc_34xx_sr = {
2849 .type = TI_SYSC_OMAP34XX_SR,
2850 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2851 .regbits = &sysc_regbits_omap34xx_sr,
2852 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2853 SYSC_QUIRK_LEGACY_IDLE,
2857 * SmartReflex sysc found on omap36xx and later
2859 static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2860 .dmadisable_shift = -ENODEV,
2861 .midle_shift = -ENODEV,
2863 .clkact_shift = -ENODEV,
2865 .srst_shift = -ENODEV,
2866 .emufree_shift = -ENODEV,
2867 .autoidle_shift = -ENODEV,
2870 static const struct sysc_capabilities sysc_36xx_sr = {
2871 .type = TI_SYSC_OMAP36XX_SR,
2872 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
2873 .regbits = &sysc_regbits_omap36xx_sr,
2874 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
2877 static const struct sysc_capabilities sysc_omap4_sr = {
2878 .type = TI_SYSC_OMAP4_SR,
2879 .regbits = &sysc_regbits_omap36xx_sr,
2880 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
2884 * McASP register bits found on omap4 and later
2886 static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2887 .dmadisable_shift = -ENODEV,
2888 .midle_shift = -ENODEV,
2890 .clkact_shift = -ENODEV,
2891 .enwkup_shift = -ENODEV,
2892 .srst_shift = -ENODEV,
2893 .emufree_shift = -ENODEV,
2894 .autoidle_shift = -ENODEV,
2897 static const struct sysc_capabilities sysc_omap4_mcasp = {
2898 .type = TI_SYSC_OMAP4_MCASP,
2899 .regbits = &sysc_regbits_omap4_mcasp,
2900 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2904 * McASP found on dra7 and later
2906 static const struct sysc_capabilities sysc_dra7_mcasp = {
2907 .type = TI_SYSC_OMAP4_SIMPLE,
2908 .regbits = &sysc_regbits_omap4_simple,
2909 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2913 * FS USB host found on omap4 and later
2915 static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2916 .dmadisable_shift = -ENODEV,
2917 .midle_shift = -ENODEV,
2919 .clkact_shift = -ENODEV,
2921 .srst_shift = -ENODEV,
2922 .emufree_shift = -ENODEV,
2923 .autoidle_shift = -ENODEV,
2926 static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2927 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2928 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2929 .regbits = &sysc_regbits_omap4_usb_host_fs,
2932 static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2933 .dmadisable_shift = -ENODEV,
2934 .midle_shift = -ENODEV,
2935 .sidle_shift = -ENODEV,
2936 .clkact_shift = -ENODEV,
2939 .emufree_shift = -ENODEV,
2940 .autoidle_shift = -ENODEV,
2943 static const struct sysc_capabilities sysc_dra7_mcan = {
2944 .type = TI_SYSC_DRA7_MCAN,
2945 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2946 .regbits = &sysc_regbits_dra7_mcan,
2947 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
2951 * PRUSS found on some AM33xx, AM437x and AM57xx SoCs
2953 static const struct sysc_capabilities sysc_pruss = {
2954 .type = TI_SYSC_PRUSS,
2955 .sysc_mask = SYSC_PRUSS_STANDBY_INIT | SYSC_PRUSS_SUB_MWAIT,
2956 .regbits = &sysc_regbits_omap4_simple,
2957 .mod_quirks = SYSC_MODULE_QUIRK_PRUSS,
2960 static int sysc_init_pdata(struct sysc *ddata)
2962 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2963 struct ti_sysc_module_data *mdata;
2968 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2972 if (ddata->legacy_mode) {
2973 mdata->name = ddata->legacy_mode;
2974 mdata->module_pa = ddata->module_pa;
2975 mdata->module_size = ddata->module_size;
2976 mdata->offsets = ddata->offsets;
2977 mdata->nr_offsets = SYSC_MAX_REGS;
2978 mdata->cap = ddata->cap;
2979 mdata->cfg = &ddata->cfg;
2982 ddata->mdata = mdata;
2987 static int sysc_init_match(struct sysc *ddata)
2989 const struct sysc_capabilities *cap;
2991 cap = of_device_get_match_data(ddata->dev);
2997 ddata->cfg.quirks |= ddata->cap->mod_quirks;
3002 static void ti_sysc_idle(struct work_struct *work)
3006 ddata = container_of(work, struct sysc, idle_work.work);
3009 * One time decrement of clock usage counts if left on from init.
3010 * Note that we disable opt clocks unconditionally in this case
3011 * as they are enabled unconditionally during init without
3012 * considering sysc_opt_clks_needed() at that point.
3014 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
3015 SYSC_QUIRK_NO_IDLE_ON_INIT)) {
3016 sysc_disable_main_clocks(ddata);
3017 sysc_disable_opt_clocks(ddata);
3018 sysc_clkdm_allow_idle(ddata);
3021 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
3022 if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE)
3026 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
3027 * and SYSC_QUIRK_NO_RESET_ON_INIT
3029 if (pm_runtime_active(ddata->dev))
3030 pm_runtime_put_sync(ddata->dev);
3034 * SoC model and features detection. Only needed for SoCs that need
3035 * special handling for quirks, no need to list others.
3037 static const struct soc_device_attribute sysc_soc_match[] = {
3038 SOC_FLAG("OMAP242*", SOC_2420),
3039 SOC_FLAG("OMAP243*", SOC_2430),
3040 SOC_FLAG("AM35*", SOC_AM35),
3041 SOC_FLAG("OMAP3[45]*", SOC_3430),
3042 SOC_FLAG("OMAP3[67]*", SOC_3630),
3043 SOC_FLAG("OMAP443*", SOC_4430),
3044 SOC_FLAG("OMAP446*", SOC_4460),
3045 SOC_FLAG("OMAP447*", SOC_4470),
3046 SOC_FLAG("OMAP54*", SOC_5430),
3047 SOC_FLAG("AM433", SOC_AM3),
3048 SOC_FLAG("AM43*", SOC_AM4),
3049 SOC_FLAG("DRA7*", SOC_DRA7),
3055 * List of SoCs variants with disabled features. By default we assume all
3056 * devices in the device tree are available so no need to list those SoCs.
3058 static const struct soc_device_attribute sysc_soc_feat_match[] = {
3059 /* OMAP3430/3530 and AM3517 variants with some accelerators disabled */
3060 SOC_FLAG("AM3505", DIS_SGX),
3061 SOC_FLAG("OMAP3525", DIS_SGX),
3062 SOC_FLAG("OMAP3515", DIS_IVA | DIS_SGX),
3063 SOC_FLAG("OMAP3503", DIS_ISP | DIS_IVA | DIS_SGX),
3065 /* OMAP3630/DM3730 variants with some accelerators disabled */
3066 SOC_FLAG("AM3703", DIS_IVA | DIS_SGX),
3067 SOC_FLAG("DM3725", DIS_SGX),
3068 SOC_FLAG("OMAP3611", DIS_ISP | DIS_IVA | DIS_SGX),
3069 SOC_FLAG("OMAP3615/AM3715", DIS_IVA),
3070 SOC_FLAG("OMAP3621", DIS_ISP),
3075 static int sysc_add_disabled(unsigned long base)
3077 struct sysc_address *disabled_module;
3079 disabled_module = kzalloc(sizeof(*disabled_module), GFP_KERNEL);
3080 if (!disabled_module)
3083 disabled_module->base = base;
3085 mutex_lock(&sysc_soc->list_lock);
3086 list_add(&disabled_module->node, &sysc_soc->disabled_modules);
3087 mutex_unlock(&sysc_soc->list_lock);
3093 * One time init to detect the booted SoC, disable unavailable features
3094 * and initialize list for optional cpu_pm notifier.
3096 * Note that we initialize static data shared across all ti-sysc instances
3097 * so ddata is only used for SoC type. This can be called from module_init
3098 * once we no longer need to rely on platform data.
3100 static int sysc_init_static_data(struct sysc *ddata)
3102 const struct soc_device_attribute *match;
3103 struct ti_sysc_platform_data *pdata;
3104 unsigned long features = 0;
3105 struct device_node *np;
3110 sysc_soc = kzalloc(sizeof(*sysc_soc), GFP_KERNEL);
3114 mutex_init(&sysc_soc->list_lock);
3115 INIT_LIST_HEAD(&sysc_soc->disabled_modules);
3116 INIT_LIST_HEAD(&sysc_soc->restored_modules);
3117 sysc_soc->general_purpose = true;
3119 pdata = dev_get_platdata(ddata->dev);
3120 if (pdata && pdata->soc_type_gp)
3121 sysc_soc->general_purpose = pdata->soc_type_gp();
3123 match = soc_device_match(sysc_soc_match);
3124 if (match && match->data)
3125 sysc_soc->soc = (enum sysc_soc)(uintptr_t)match->data;
3128 * Check and warn about possible old incomplete dtb. We now want to see
3129 * simple-pm-bus instead of simple-bus in the dtb for genpd using SoCs.
3131 switch (sysc_soc->soc) {
3134 case SOC_4430 ... SOC_4470:
3137 np = of_find_node_by_path("/ocp");
3138 WARN_ONCE(np && of_device_is_compatible(np, "simple-bus"),
3139 "ti-sysc: Incomplete old dtb, please update\n");
3145 /* Ignore devices that are not available on HS and EMU SoCs */
3146 if (!sysc_soc->general_purpose) {
3147 switch (sysc_soc->soc) {
3148 case SOC_3430 ... SOC_3630:
3149 sysc_add_disabled(0x48304000); /* timer12 */
3152 sysc_add_disabled(0x48310000); /* rng */
3159 match = soc_device_match(sysc_soc_feat_match);
3164 features = (unsigned long)match->data;
3167 * Add disabled devices to the list based on the module base.
3168 * Note that this must be done before we attempt to access the
3169 * device and have module revision checks working.
3171 if (features & DIS_ISP)
3172 sysc_add_disabled(0x480bd400);
3173 if (features & DIS_IVA)
3174 sysc_add_disabled(0x5d000000);
3175 if (features & DIS_SGX)
3176 sysc_add_disabled(0x50000000);
3181 static void sysc_cleanup_static_data(void)
3183 struct sysc_module *restored_module;
3184 struct sysc_address *disabled_module;
3185 struct list_head *pos, *tmp;
3190 if (sysc_soc->nb.notifier_call)
3191 cpu_pm_unregister_notifier(&sysc_soc->nb);
3193 mutex_lock(&sysc_soc->list_lock);
3194 list_for_each_safe(pos, tmp, &sysc_soc->restored_modules) {
3195 restored_module = list_entry(pos, struct sysc_module, node);
3197 kfree(restored_module);
3199 list_for_each_safe(pos, tmp, &sysc_soc->disabled_modules) {
3200 disabled_module = list_entry(pos, struct sysc_address, node);
3202 kfree(disabled_module);
3204 mutex_unlock(&sysc_soc->list_lock);
3207 static int sysc_check_disabled_devices(struct sysc *ddata)
3209 struct sysc_address *disabled_module;
3212 mutex_lock(&sysc_soc->list_lock);
3213 list_for_each_entry(disabled_module, &sysc_soc->disabled_modules, node) {
3214 if (ddata->module_pa == disabled_module->base) {
3215 dev_dbg(ddata->dev, "module disabled for this SoC\n");
3220 mutex_unlock(&sysc_soc->list_lock);
3226 * Ignore timers tagged with no-reset and no-idle. These are likely in use,
3227 * for example by drivers/clocksource/timer-ti-dm-systimer.c. If more checks
3228 * are needed, we could also look at the timer register configuration.
3230 static int sysc_check_active_timer(struct sysc *ddata)
3234 if (ddata->cap->type != TI_SYSC_OMAP2_TIMER &&
3235 ddata->cap->type != TI_SYSC_OMAP4_TIMER)
3239 * Quirk for omap3 beagleboard revision A to B4 to use gpt12.
3240 * Revision C and later are fixed with commit 23885389dbbb ("ARM:
3241 * dts: Fix timer regression for beagleboard revision c"). This all
3242 * can be dropped if we stop supporting old beagleboard revisions
3243 * A to B4 at some point.
3245 if (sysc_soc->soc == SOC_3430 || sysc_soc->soc == SOC_AM35)
3250 if ((ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) &&
3251 (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE))
3257 static const struct of_device_id sysc_match_table[] = {
3258 { .compatible = "simple-bus", },
3262 static int sysc_probe(struct platform_device *pdev)
3264 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
3268 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
3272 ddata->offsets[SYSC_REVISION] = -ENODEV;
3273 ddata->offsets[SYSC_SYSCONFIG] = -ENODEV;
3274 ddata->offsets[SYSC_SYSSTATUS] = -ENODEV;
3275 ddata->dev = &pdev->dev;
3276 platform_set_drvdata(pdev, ddata);
3278 error = sysc_init_static_data(ddata);
3282 error = sysc_init_match(ddata);
3286 error = sysc_init_dts_quirks(ddata);
3290 error = sysc_map_and_check_registers(ddata);
3294 error = sysc_init_sysc_mask(ddata);
3298 error = sysc_init_idlemodes(ddata);
3302 error = sysc_init_syss_mask(ddata);
3306 error = sysc_init_pdata(ddata);
3310 sysc_init_early_quirks(ddata);
3312 error = sysc_check_disabled_devices(ddata);
3316 error = sysc_check_active_timer(ddata);
3317 if (error == -ENXIO)
3318 ddata->reserved = true;
3322 error = sysc_get_clocks(ddata);
3326 error = sysc_init_resets(ddata);
3330 error = sysc_init_module(ddata);
3334 pm_runtime_enable(ddata->dev);
3335 error = pm_runtime_resume_and_get(ddata->dev);
3337 pm_runtime_disable(ddata->dev);
3341 /* Balance use counts as PM runtime should have enabled these all */
3342 if (!(ddata->cfg.quirks &
3343 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))) {
3344 sysc_disable_main_clocks(ddata);
3345 sysc_disable_opt_clocks(ddata);
3346 sysc_clkdm_allow_idle(ddata);
3349 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
3350 reset_control_assert(ddata->rsts);
3352 sysc_show_registers(ddata);
3354 ddata->dev->type = &sysc_device_type;
3356 if (!ddata->reserved) {
3357 error = of_platform_populate(ddata->dev->of_node,
3359 pdata ? pdata->auxdata : NULL,
3365 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
3367 /* At least earlycon won't survive without deferred idle */
3368 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
3369 SYSC_QUIRK_NO_IDLE_ON_INIT |
3370 SYSC_QUIRK_NO_RESET_ON_INIT)) {
3371 schedule_delayed_work(&ddata->idle_work, 3000);
3373 pm_runtime_put(&pdev->dev);
3376 if (ddata->cfg.quirks & SYSC_QUIRK_REINIT_ON_CTX_LOST)
3377 sysc_add_restored(ddata);
3382 pm_runtime_put_sync(&pdev->dev);
3383 pm_runtime_disable(&pdev->dev);
3385 sysc_unprepare(ddata);
3390 static int sysc_remove(struct platform_device *pdev)
3392 struct sysc *ddata = platform_get_drvdata(pdev);
3395 /* Device can still be enabled, see deferred idle quirk in probe */
3396 if (cancel_delayed_work_sync(&ddata->idle_work))
3397 ti_sysc_idle(&ddata->idle_work.work);
3399 error = pm_runtime_resume_and_get(ddata->dev);
3401 pm_runtime_disable(ddata->dev);
3405 of_platform_depopulate(&pdev->dev);
3407 pm_runtime_put_sync(&pdev->dev);
3408 pm_runtime_disable(&pdev->dev);
3410 if (!reset_control_status(ddata->rsts))
3411 reset_control_assert(ddata->rsts);
3414 sysc_unprepare(ddata);
3419 static const struct of_device_id sysc_match[] = {
3420 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
3421 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
3422 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
3423 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
3424 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
3425 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
3426 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
3427 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
3428 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
3429 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
3430 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
3431 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
3432 { .compatible = "ti,sysc-usb-host-fs",
3433 .data = &sysc_omap4_usb_host_fs, },
3434 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
3435 { .compatible = "ti,sysc-pruss", .data = &sysc_pruss, },
3438 MODULE_DEVICE_TABLE(of, sysc_match);
3440 static struct platform_driver sysc_driver = {
3441 .probe = sysc_probe,
3442 .remove = sysc_remove,
3445 .of_match_table = sysc_match,
3450 static int __init sysc_init(void)
3452 bus_register_notifier(&platform_bus_type, &sysc_nb);
3454 return platform_driver_register(&sysc_driver);
3456 module_init(sysc_init);
3458 static void __exit sysc_exit(void)
3460 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
3461 platform_driver_unregister(&sysc_driver);
3462 sysc_cleanup_static_data();
3464 module_exit(sysc_exit);
3466 MODULE_DESCRIPTION("TI sysc interconnect target driver");
3467 MODULE_LICENSE("GPL v2");