blob: da88de487792ee2b36d784c27c0ad04b68cff546 [file] [log] [blame]
Tony Lindgren0eecc632017-10-10 14:23:43 -07001/*
2 * ti-sysc.c - Texas Instruments sysc interconnect target driver
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/io.h>
15#include <linux/clk.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080016#include <linux/clkdev.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080017#include <linux/delay.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070018#include <linux/module.h>
19#include <linux/platform_device.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080020#include <linux/pm_domain.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070021#include <linux/pm_runtime.h>
Tony Lindgren50622362018-04-16 10:20:27 -070022#include <linux/reset.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070023#include <linux/of_address.h>
24#include <linux/of_platform.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080025#include <linux/slab.h>
Faiz Abbas596e7952018-07-09 22:18:39 +053026#include <linux/iopoll.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080027
Tony Lindgren70a65242017-12-15 09:41:09 -080028#include <linux/platform_data/ti-sysc.h>
29
30#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070031
Faiz Abbas596e7952018-07-09 22:18:39 +053032#define MAX_MODULE_SOFTRESET_WAIT 10000
33
Tony Lindgren0eecc632017-10-10 14:23:43 -070034static const char * const reg_names[] = { "rev", "sysc", "syss", };
35
36enum sysc_clocks {
37 SYSC_FCK,
38 SYSC_ICK,
Tony Lindgren09dfe582018-04-16 10:25:52 -070039 SYSC_OPTFCK0,
40 SYSC_OPTFCK1,
41 SYSC_OPTFCK2,
42 SYSC_OPTFCK3,
43 SYSC_OPTFCK4,
44 SYSC_OPTFCK5,
45 SYSC_OPTFCK6,
46 SYSC_OPTFCK7,
Tony Lindgren0eecc632017-10-10 14:23:43 -070047 SYSC_MAX_CLOCKS,
48};
49
Tony Lindgrena54275f2019-03-21 11:00:21 -070050static const char * const clock_names[SYSC_MAX_CLOCKS] = {
51 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
52 "opt5", "opt6", "opt7",
53};
Tony Lindgren0eecc632017-10-10 14:23:43 -070054
Tony Lindgrenc5a2de92017-12-15 09:41:23 -080055#define SYSC_IDLEMODE_MASK 3
56#define SYSC_CLOCKACTIVITY_MASK 3
57
Tony Lindgren0eecc632017-10-10 14:23:43 -070058/**
59 * struct sysc - TI sysc interconnect target module registers and capabilities
60 * @dev: struct device pointer
61 * @module_pa: physical address of the interconnect target module
62 * @module_size: size of the interconnect target module
63 * @module_va: virtual address of the interconnect target module
64 * @offsets: register offsets from module base
65 * @clocks: clocks used by the interconnect target module
Tony Lindgren09dfe582018-04-16 10:25:52 -070066 * @clock_roles: clock role names for the found clocks
67 * @nr_clocks: number of clocks used by the interconnect target module
Tony Lindgren0eecc632017-10-10 14:23:43 -070068 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -080069 * @cap: interconnect target module capabilities
70 * @cfg: interconnect target module configuration
Tony Lindgren566a9b052017-12-15 09:41:19 -080071 * @name: name if available
72 * @revision: interconnect target module revision
Tony Lindgren62020f22018-02-22 13:59:44 -080073 * @needs_resume: runtime resume needed on resume from suspend
Tony Lindgren4e23be42019-06-10 04:48:05 -070074 * @clk_enable_quirk: module specific clock enable quirk
75 * @clk_disable_quirk: module specific clock disable quirk
76 * @reset_done_quirk: module specific reset done quirk
Tony Lindgren0eecc632017-10-10 14:23:43 -070077 */
78struct sysc {
79 struct device *dev;
80 u64 module_pa;
81 u32 module_size;
82 void __iomem *module_va;
83 int offsets[SYSC_MAX_REGS];
Tony Lindgrena3e92e72019-03-21 11:00:21 -070084 struct ti_sysc_module_data *mdata;
Tony Lindgren09dfe582018-04-16 10:25:52 -070085 struct clk **clocks;
86 const char **clock_roles;
87 int nr_clocks;
Tony Lindgren50622362018-04-16 10:20:27 -070088 struct reset_control *rsts;
Tony Lindgren0eecc632017-10-10 14:23:43 -070089 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -080090 const struct sysc_capabilities *cap;
91 struct sysc_config cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -080092 struct ti_sysc_cookie cookie;
Tony Lindgren566a9b052017-12-15 09:41:19 -080093 const char *name;
94 u32 revision;
Tony Lindgren8383e252019-05-27 04:51:56 -070095 unsigned int enabled:1;
96 unsigned int needs_resume:1;
97 unsigned int child_needs_resume:1;
98 unsigned int disable_on_idle:1;
Tony Lindgren76f0f772018-02-23 08:28:45 -080099 struct delayed_work idle_work;
Tony Lindgren4e23be42019-06-10 04:48:05 -0700100 void (*clk_enable_quirk)(struct sysc *sysc);
101 void (*clk_disable_quirk)(struct sysc *sysc);
102 void (*reset_done_quirk)(struct sysc *sysc);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700103};
104
Tony Lindgren4014c082018-12-10 14:11:26 -0800105static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
106 bool is_child);
107
Tony Lindgrenb7182b42019-03-21 11:00:21 -0700108static void sysc_write(struct sysc *ddata, int offset, u32 value)
Faiz Abbas596e7952018-07-09 22:18:39 +0530109{
Tony Lindgren5aa91292019-05-27 04:51:53 -0700110 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
111 writew_relaxed(value & 0xffff, ddata->module_va + offset);
112
113 /* Only i2c revision has LO and HI register with stride of 4 */
114 if (ddata->offsets[SYSC_REVISION] >= 0 &&
115 offset == ddata->offsets[SYSC_REVISION]) {
116 u16 hi = value >> 16;
117
118 writew_relaxed(hi, ddata->module_va + offset + 4);
119 }
120
121 return;
122 }
123
Faiz Abbas596e7952018-07-09 22:18:39 +0530124 writel_relaxed(value, ddata->module_va + offset);
125}
126
Tony Lindgren566a9b052017-12-15 09:41:19 -0800127static u32 sysc_read(struct sysc *ddata, int offset)
128{
129 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
130 u32 val;
131
132 val = readw_relaxed(ddata->module_va + offset);
Tony Lindgren5aa91292019-05-27 04:51:53 -0700133
134 /* Only i2c revision has LO and HI register with stride of 4 */
135 if (ddata->offsets[SYSC_REVISION] >= 0 &&
136 offset == ddata->offsets[SYSC_REVISION]) {
137 u16 tmp = readw_relaxed(ddata->module_va + offset + 4);
138
139 val |= tmp << 16;
140 }
Tony Lindgren566a9b052017-12-15 09:41:19 -0800141
142 return val;
143 }
144
145 return readl_relaxed(ddata->module_va + offset);
146}
147
Tony Lindgren09dfe582018-04-16 10:25:52 -0700148static bool sysc_opt_clks_needed(struct sysc *ddata)
149{
150 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
151}
152
Tony Lindgren0eecc632017-10-10 14:23:43 -0700153static u32 sysc_read_revision(struct sysc *ddata)
154{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800155 int offset = ddata->offsets[SYSC_REVISION];
156
157 if (offset < 0)
158 return 0;
159
160 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700161}
162
Tony Lindgrene0db94f2019-05-27 04:51:53 -0700163static u32 sysc_read_sysconfig(struct sysc *ddata)
164{
165 int offset = ddata->offsets[SYSC_SYSCONFIG];
166
167 if (offset < 0)
168 return 0;
169
170 return sysc_read(ddata, offset);
171}
172
173static u32 sysc_read_sysstatus(struct sysc *ddata)
174{
175 int offset = ddata->offsets[SYSC_SYSSTATUS];
176
177 if (offset < 0)
178 return 0;
179
180 return sysc_read(ddata, offset);
181}
182
Tony Lindgrena54275f2019-03-21 11:00:21 -0700183static int sysc_add_named_clock_from_child(struct sysc *ddata,
184 const char *name,
185 const char *optfck_name)
186{
187 struct device_node *np = ddata->dev->of_node;
188 struct device_node *child;
189 struct clk_lookup *cl;
190 struct clk *clock;
191 const char *n;
192
193 if (name)
194 n = name;
195 else
196 n = optfck_name;
197
198 /* Does the clock alias already exist? */
199 clock = of_clk_get_by_name(np, n);
200 if (!IS_ERR(clock)) {
201 clk_put(clock);
202
203 return 0;
204 }
205
206 child = of_get_next_available_child(np, NULL);
207 if (!child)
208 return -ENODEV;
209
210 clock = devm_get_clk_from_child(ddata->dev, child, name);
211 if (IS_ERR(clock))
212 return PTR_ERR(clock);
213
214 /*
215 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
216 * limit for clk_get(). If cl ever needs to be freed, it should be done
217 * with clkdev_drop().
218 */
219 cl = kcalloc(1, sizeof(*cl), GFP_KERNEL);
220 if (!cl)
221 return -ENOMEM;
222
223 cl->con_id = n;
224 cl->dev_id = dev_name(ddata->dev);
225 cl->clk = clock;
226 clkdev_add(cl);
227
228 clk_put(clock);
229
230 return 0;
231}
232
233static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
234{
235 const char *optfck_name;
236 int error, index;
237
238 if (ddata->nr_clocks < SYSC_OPTFCK0)
239 index = SYSC_OPTFCK0;
240 else
241 index = ddata->nr_clocks;
242
243 if (name)
244 optfck_name = name;
245 else
246 optfck_name = clock_names[index];
247
248 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
249 if (error)
250 return error;
251
252 ddata->clock_roles[index] = optfck_name;
253 ddata->nr_clocks++;
254
255 return 0;
256}
257
Tony Lindgren09dfe582018-04-16 10:25:52 -0700258static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700259{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700260 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700261
Tony Lindgren09dfe582018-04-16 10:25:52 -0700262 if (!strncmp(clock_names[SYSC_FCK], name, 3))
263 index = SYSC_FCK;
264 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
265 index = SYSC_ICK;
266
267 if (index < 0) {
268 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700269 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700270 index = i;
271 break;
272 }
273 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700274 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700275
276 if (index < 0) {
277 dev_err(ddata->dev, "clock %s not added\n", name);
278 return index;
279 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700280
281 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
282 if (IS_ERR(ddata->clocks[index])) {
283 if (PTR_ERR(ddata->clocks[index]) == -ENOENT)
284 return 0;
285
286 dev_err(ddata->dev, "clock get error for %s: %li\n",
287 name, PTR_ERR(ddata->clocks[index]));
288
289 return PTR_ERR(ddata->clocks[index]);
290 }
291
292 error = clk_prepare(ddata->clocks[index]);
293 if (error) {
294 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
295 name, error);
296
297 return error;
298 }
299
300 return 0;
301}
302
303static int sysc_get_clocks(struct sysc *ddata)
304{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700305 struct device_node *np = ddata->dev->of_node;
306 struct property *prop;
307 const char *name;
308 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700309
Kees Cook20749052018-06-18 10:45:49 -0700310 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700311 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700312 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700313 GFP_KERNEL);
314 if (!ddata->clock_roles)
315 return -ENOMEM;
316
317 of_property_for_each_string(np, "clock-names", prop, name) {
318 if (!strncmp(clock_names[SYSC_FCK], name, 3))
319 nr_fck++;
320 if (!strncmp(clock_names[SYSC_ICK], name, 3))
321 nr_ick++;
322 ddata->clock_roles[ddata->nr_clocks] = name;
323 ddata->nr_clocks++;
324 }
325
326 if (ddata->nr_clocks < 1)
327 return 0;
328
Tony Lindgrena54275f2019-03-21 11:00:21 -0700329 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
330 error = sysc_init_ext_opt_clock(ddata, NULL);
331 if (error)
332 return error;
333 }
334
Tony Lindgren09dfe582018-04-16 10:25:52 -0700335 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
336 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
337
338 return -EINVAL;
339 }
340
341 if (nr_fck > 1 || nr_ick > 1) {
342 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
343
344 return -EINVAL;
345 }
346
Kees Cook20749052018-06-18 10:45:49 -0700347 ddata->clocks = devm_kcalloc(ddata->dev,
348 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700349 GFP_KERNEL);
350 if (!ddata->clocks)
351 return -ENOMEM;
352
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800353 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
354 const char *name = ddata->clock_roles[i];
355
356 if (!name)
357 continue;
358
359 error = sysc_get_one_clock(ddata, name);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700360 if (error && error != -ENOENT)
361 return error;
362 }
363
364 return 0;
365}
366
Tony Lindgrend8789702019-03-21 11:00:21 -0700367static int sysc_enable_main_clocks(struct sysc *ddata)
368{
369 struct clk *clock;
370 int i, error;
371
372 if (!ddata->clocks)
373 return 0;
374
375 for (i = 0; i < SYSC_OPTFCK0; i++) {
376 clock = ddata->clocks[i];
377
378 /* Main clocks may not have ick */
379 if (IS_ERR_OR_NULL(clock))
380 continue;
381
382 error = clk_enable(clock);
383 if (error)
384 goto err_disable;
385 }
386
387 return 0;
388
389err_disable:
390 for (i--; i >= 0; i--) {
391 clock = ddata->clocks[i];
392
393 /* Main clocks may not have ick */
394 if (IS_ERR_OR_NULL(clock))
395 continue;
396
397 clk_disable(clock);
398 }
399
400 return error;
401}
402
403static void sysc_disable_main_clocks(struct sysc *ddata)
404{
405 struct clk *clock;
406 int i;
407
408 if (!ddata->clocks)
409 return;
410
411 for (i = 0; i < SYSC_OPTFCK0; i++) {
412 clock = ddata->clocks[i];
413 if (IS_ERR_OR_NULL(clock))
414 continue;
415
416 clk_disable(clock);
417 }
418}
419
420static int sysc_enable_opt_clocks(struct sysc *ddata)
421{
422 struct clk *clock;
423 int i, error;
424
425 if (!ddata->clocks)
426 return 0;
427
428 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
429 clock = ddata->clocks[i];
430
431 /* Assume no holes for opt clocks */
432 if (IS_ERR_OR_NULL(clock))
433 return 0;
434
435 error = clk_enable(clock);
436 if (error)
437 goto err_disable;
438 }
439
440 return 0;
441
442err_disable:
443 for (i--; i >= 0; i--) {
444 clock = ddata->clocks[i];
445 if (IS_ERR_OR_NULL(clock))
446 continue;
447
448 clk_disable(clock);
449 }
450
451 return error;
452}
453
454static void sysc_disable_opt_clocks(struct sysc *ddata)
455{
456 struct clk *clock;
457 int i;
458
459 if (!ddata->clocks)
460 return;
461
462 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
463 clock = ddata->clocks[i];
464
465 /* Assume no holes for opt clocks */
466 if (IS_ERR_OR_NULL(clock))
467 return;
468
469 clk_disable(clock);
470 }
471}
472
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700473static void sysc_clkdm_deny_idle(struct sysc *ddata)
474{
475 struct ti_sysc_platform_data *pdata;
476
477 if (ddata->legacy_mode)
478 return;
479
480 pdata = dev_get_platdata(ddata->dev);
481 if (pdata && pdata->clkdm_deny_idle)
482 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
483}
484
485static void sysc_clkdm_allow_idle(struct sysc *ddata)
486{
487 struct ti_sysc_platform_data *pdata;
488
489 if (ddata->legacy_mode)
490 return;
491
492 pdata = dev_get_platdata(ddata->dev);
493 if (pdata && pdata->clkdm_allow_idle)
494 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
495}
496
Tony Lindgren0eecc632017-10-10 14:23:43 -0700497/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700498 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700499 * @ddata: device driver data
500 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700501 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700502 */
503static int sysc_init_resets(struct sysc *ddata)
504{
Tony Lindgren50622362018-04-16 10:20:27 -0700505 ddata->rsts =
Tony Lindgrenea5a2e42019-05-27 04:51:56 -0700506 devm_reset_control_get_optional(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700507 if (IS_ERR(ddata->rsts))
508 return PTR_ERR(ddata->rsts);
509
Tony Lindgren50622362018-04-16 10:20:27 -0700510 return 0;
511}
512
513/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700514 * sysc_parse_and_check_child_range - parses module IO region from ranges
515 * @ddata: device driver data
516 *
517 * In general we only need rev, syss, and sysc registers and not the whole
518 * module range. But we do want the offsets for these registers from the
519 * module base. This allows us to check them against the legacy hwmod
520 * platform data. Let's also check the ranges are configured properly.
521 */
522static int sysc_parse_and_check_child_range(struct sysc *ddata)
523{
524 struct device_node *np = ddata->dev->of_node;
525 const __be32 *ranges;
526 u32 nr_addr, nr_size;
527 int len, error;
528
529 ranges = of_get_property(np, "ranges", &len);
530 if (!ranges) {
531 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
532
533 return -ENOENT;
534 }
535
536 len /= sizeof(*ranges);
537
538 if (len < 3) {
539 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
540
541 return -EINVAL;
542 }
543
544 error = of_property_read_u32(np, "#address-cells", &nr_addr);
545 if (error)
546 return -ENOENT;
547
548 error = of_property_read_u32(np, "#size-cells", &nr_size);
549 if (error)
550 return -ENOENT;
551
552 if (nr_addr != 1 || nr_size != 1) {
553 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
554
555 return -EINVAL;
556 }
557
558 ranges++;
559 ddata->module_pa = of_translate_address(np, ranges++);
560 ddata->module_size = be32_to_cpup(ranges);
561
Tony Lindgren0eecc632017-10-10 14:23:43 -0700562 return 0;
563}
564
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800565static struct device_node *stdout_path;
566
567static void sysc_init_stdout_path(struct sysc *ddata)
568{
569 struct device_node *np = NULL;
570 const char *uart;
571
572 if (IS_ERR(stdout_path))
573 return;
574
575 if (stdout_path)
576 return;
577
578 np = of_find_node_by_path("/chosen");
579 if (!np)
580 goto err;
581
582 uart = of_get_property(np, "stdout-path", NULL);
583 if (!uart)
584 goto err;
585
586 np = of_find_node_by_path(uart);
587 if (!np)
588 goto err;
589
590 stdout_path = np;
591
592 return;
593
594err:
595 stdout_path = ERR_PTR(-ENODEV);
596}
597
598static void sysc_check_quirk_stdout(struct sysc *ddata,
599 struct device_node *np)
600{
601 sysc_init_stdout_path(ddata);
602 if (np != stdout_path)
603 return;
604
605 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
606 SYSC_QUIRK_NO_RESET_ON_INIT;
607}
608
Tony Lindgren0eecc632017-10-10 14:23:43 -0700609/**
610 * sysc_check_one_child - check child configuration
611 * @ddata: device driver data
612 * @np: child device node
613 *
614 * Let's avoid messy situations where we have new interconnect target
615 * node but children have "ti,hwmods". These belong to the interconnect
616 * target node and are managed by this driver.
617 */
618static int sysc_check_one_child(struct sysc *ddata,
619 struct device_node *np)
620{
621 const char *name;
622
623 name = of_get_property(np, "ti,hwmods", NULL);
624 if (name)
625 dev_warn(ddata->dev, "really a child ti,hwmods property?");
626
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800627 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800628 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800629
Tony Lindgren0eecc632017-10-10 14:23:43 -0700630 return 0;
631}
632
633static int sysc_check_children(struct sysc *ddata)
634{
635 struct device_node *child;
636 int error;
637
638 for_each_child_of_node(ddata->dev->of_node, child) {
639 error = sysc_check_one_child(ddata, child);
640 if (error)
641 return error;
642 }
643
644 return 0;
645}
646
Tony Lindgrena7199e22017-12-15 09:41:14 -0800647/*
648 * So far only I2C uses 16-bit read access with clockactivity with revision
649 * in two registers with stride of 4. We can detect this based on the rev
650 * register size to configure things far enough to be able to properly read
651 * the revision register.
652 */
653static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
654{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800655 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800656 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800657}
658
Tony Lindgren0eecc632017-10-10 14:23:43 -0700659/**
660 * sysc_parse_one - parses the interconnect target module registers
661 * @ddata: device driver data
662 * @reg: register to parse
663 */
664static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
665{
666 struct resource *res;
667 const char *name;
668
669 switch (reg) {
670 case SYSC_REVISION:
671 case SYSC_SYSCONFIG:
672 case SYSC_SYSSTATUS:
673 name = reg_names[reg];
674 break;
675 default:
676 return -EINVAL;
677 }
678
679 res = platform_get_resource_byname(to_platform_device(ddata->dev),
680 IORESOURCE_MEM, name);
681 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700682 ddata->offsets[reg] = -ENODEV;
683
684 return 0;
685 }
686
687 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800688 if (reg == SYSC_REVISION)
689 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700690
691 return 0;
692}
693
694static int sysc_parse_registers(struct sysc *ddata)
695{
696 int i, error;
697
698 for (i = 0; i < SYSC_MAX_REGS; i++) {
699 error = sysc_parse_one(ddata, i);
700 if (error)
701 return error;
702 }
703
704 return 0;
705}
706
707/**
708 * sysc_check_registers - check for misconfigured register overlaps
709 * @ddata: device driver data
710 */
711static int sysc_check_registers(struct sysc *ddata)
712{
713 int i, j, nr_regs = 0, nr_matches = 0;
714
715 for (i = 0; i < SYSC_MAX_REGS; i++) {
716 if (ddata->offsets[i] < 0)
717 continue;
718
719 if (ddata->offsets[i] > (ddata->module_size - 4)) {
720 dev_err(ddata->dev, "register outside module range");
721
722 return -EINVAL;
723 }
724
725 for (j = 0; j < SYSC_MAX_REGS; j++) {
726 if (ddata->offsets[j] < 0)
727 continue;
728
729 if (ddata->offsets[i] == ddata->offsets[j])
730 nr_matches++;
731 }
732 nr_regs++;
733 }
734
Tony Lindgren0eecc632017-10-10 14:23:43 -0700735 if (nr_matches > nr_regs) {
736 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
737 nr_regs, nr_matches);
738
739 return -EINVAL;
740 }
741
742 return 0;
743}
744
745/**
746 * syc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700747 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700748 *
749 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700750 * within the interconnect target module range. For example, SGX has
751 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
752 * has them at offset 0x1200 in the CPSW_WR child. Usually the
753 * the interconnect target module registers are at the beginning of
754 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700755 */
756static int sysc_ioremap(struct sysc *ddata)
757{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700758 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700759
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700760 if (ddata->offsets[SYSC_REVISION] < 0 &&
761 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
762 ddata->offsets[SYSC_SYSSTATUS] < 0) {
763 size = ddata->module_size;
764 } else {
765 size = max3(ddata->offsets[SYSC_REVISION],
766 ddata->offsets[SYSC_SYSCONFIG],
767 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700768
Tony Lindgren4e23be42019-06-10 04:48:05 -0700769 if (size < SZ_1K)
770 size = SZ_1K;
771
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700772 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700773 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700774 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700775
Tony Lindgren0eecc632017-10-10 14:23:43 -0700776 ddata->module_va = devm_ioremap(ddata->dev,
777 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700778 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700779 if (!ddata->module_va)
780 return -EIO;
781
782 return 0;
783}
784
785/**
786 * sysc_map_and_check_registers - ioremap and check device registers
787 * @ddata: device driver data
788 */
789static int sysc_map_and_check_registers(struct sysc *ddata)
790{
791 int error;
792
793 error = sysc_parse_and_check_child_range(ddata);
794 if (error)
795 return error;
796
797 error = sysc_check_children(ddata);
798 if (error)
799 return error;
800
801 error = sysc_parse_registers(ddata);
802 if (error)
803 return error;
804
805 error = sysc_ioremap(ddata);
806 if (error)
807 return error;
808
809 error = sysc_check_registers(ddata);
810 if (error)
811 return error;
812
813 return 0;
814}
815
816/**
817 * sysc_show_rev - read and show interconnect target module revision
818 * @bufp: buffer to print the information to
819 * @ddata: device driver data
820 */
821static int sysc_show_rev(char *bufp, struct sysc *ddata)
822{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800823 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700824
825 if (ddata->offsets[SYSC_REVISION] < 0)
826 return sprintf(bufp, ":NA");
827
Tony Lindgren566a9b052017-12-15 09:41:19 -0800828 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700829
830 return len;
831}
832
833static int sysc_show_reg(struct sysc *ddata,
834 char *bufp, enum sysc_registers reg)
835{
836 if (ddata->offsets[reg] < 0)
837 return sprintf(bufp, ":NA");
838
839 return sprintf(bufp, ":%x", ddata->offsets[reg]);
840}
841
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800842static int sysc_show_name(char *bufp, struct sysc *ddata)
843{
844 if (!ddata->name)
845 return 0;
846
847 return sprintf(bufp, ":%s", ddata->name);
848}
849
Tony Lindgren0eecc632017-10-10 14:23:43 -0700850/**
851 * sysc_show_registers - show information about interconnect target module
852 * @ddata: device driver data
853 */
854static void sysc_show_registers(struct sysc *ddata)
855{
856 char buf[128];
857 char *bufp = buf;
858 int i;
859
860 for (i = 0; i < SYSC_MAX_REGS; i++)
861 bufp += sysc_show_reg(ddata, bufp, i);
862
863 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800864 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700865
866 dev_dbg(ddata->dev, "%llx:%x%s\n",
867 ddata->module_pa, ddata->module_size,
868 buf);
869}
870
Roger Quadrosd59b6052019-04-08 12:52:39 +0300871#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700872#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +0300873
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700874/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300875static int sysc_enable_module(struct device *dev)
876{
877 struct sysc *ddata;
878 const struct sysc_regbits *regbits;
879 u32 reg, idlemodes, best_mode;
880
881 ddata = dev_get_drvdata(dev);
882 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
883 return 0;
884
Roger Quadrosd59b6052019-04-08 12:52:39 +0300885 regbits = ddata->cap->regbits;
886 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
887
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700888 /* Set CLOCKACTIVITY, we only use it for ick */
889 if (regbits->clkact_shift >= 0 &&
890 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT ||
891 ddata->cfg.sysc_val & BIT(regbits->clkact_shift)))
892 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
893
Roger Quadrosd59b6052019-04-08 12:52:39 +0300894 /* Set SIDLE mode */
895 idlemodes = ddata->cfg.sidlemodes;
896 if (!idlemodes || regbits->sidle_shift < 0)
897 goto set_midle;
898
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700899 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
900 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
901 best_mode = SYSC_IDLE_NO;
902 } else {
903 best_mode = fls(ddata->cfg.sidlemodes) - 1;
904 if (best_mode > SYSC_IDLE_MASK) {
905 dev_err(dev, "%s: invalid sidlemode\n", __func__);
906 return -EINVAL;
907 }
Tony Lindgren6e09f492019-05-27 04:51:55 -0700908
909 /* Set WAKEUP */
910 if (regbits->enwkup_shift >= 0 &&
911 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
912 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +0300913 }
914
915 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
916 reg |= best_mode << regbits->sidle_shift;
917 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
918
919set_midle:
920 /* Set MIDLE mode */
921 idlemodes = ddata->cfg.midlemodes;
922 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -0700923 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +0300924
925 best_mode = fls(ddata->cfg.midlemodes) - 1;
926 if (best_mode > SYSC_IDLE_MASK) {
927 dev_err(dev, "%s: invalid midlemode\n", __func__);
928 return -EINVAL;
929 }
930
931 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
932 reg |= best_mode << regbits->midle_shift;
933 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
934
Tony Lindgreneec26552019-05-27 04:51:54 -0700935set_autoidle:
936 /* Autoidle bit must enabled separately if available */
937 if (regbits->autoidle_shift >= 0 &&
938 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
939 reg |= 1 << regbits->autoidle_shift;
940 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
941 }
942
Roger Quadrosd59b6052019-04-08 12:52:39 +0300943 return 0;
944}
945
946static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
947{
948 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
949 *best_mode = SYSC_IDLE_SMART_WKUP;
950 else if (idlemodes & BIT(SYSC_IDLE_SMART))
951 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -0700952 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +0300953 *best_mode = SYSC_IDLE_FORCE;
954 else
955 return -EINVAL;
956
957 return 0;
958}
959
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700960/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300961static int sysc_disable_module(struct device *dev)
962{
963 struct sysc *ddata;
964 const struct sysc_regbits *regbits;
965 u32 reg, idlemodes, best_mode;
966 int ret;
967
968 ddata = dev_get_drvdata(dev);
969 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
970 return 0;
971
Roger Quadrosd59b6052019-04-08 12:52:39 +0300972 regbits = ddata->cap->regbits;
973 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
974
975 /* Set MIDLE mode */
976 idlemodes = ddata->cfg.midlemodes;
977 if (!idlemodes || regbits->midle_shift < 0)
978 goto set_sidle;
979
980 ret = sysc_best_idle_mode(idlemodes, &best_mode);
981 if (ret) {
982 dev_err(dev, "%s: invalid midlemode\n", __func__);
983 return ret;
984 }
985
986 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
987 reg |= best_mode << regbits->midle_shift;
988 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
989
990set_sidle:
991 /* Set SIDLE mode */
992 idlemodes = ddata->cfg.sidlemodes;
993 if (!idlemodes || regbits->sidle_shift < 0)
994 return 0;
995
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700996 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
997 best_mode = SYSC_IDLE_FORCE;
998 } else {
999 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1000 if (ret) {
1001 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1002 return ret;
1003 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001004 }
1005
1006 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1007 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -07001008 if (regbits->autoidle_shift >= 0 &&
1009 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1010 reg |= 1 << regbits->autoidle_shift;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001011 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
1012
1013 return 0;
1014}
1015
Tony Lindgrenff437282019-03-21 11:00:21 -07001016static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1017 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001018{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001019 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001020 int error;
1021
1022 pdata = dev_get_platdata(ddata->dev);
1023 if (!pdata)
1024 return 0;
1025
1026 if (!pdata->idle_module)
1027 return -ENODEV;
1028
1029 error = pdata->idle_module(dev, &ddata->cookie);
1030 if (error)
1031 dev_err(dev, "%s: could not idle: %i\n",
1032 __func__, error);
1033
Tony Lindgren8383e252019-05-27 04:51:56 -07001034 if (ddata->disable_on_idle)
1035 reset_control_assert(ddata->rsts);
1036
Tony Lindgrenff437282019-03-21 11:00:21 -07001037 return 0;
1038}
1039
1040static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1041 struct sysc *ddata)
1042{
1043 struct ti_sysc_platform_data *pdata;
1044 int error;
1045
Tony Lindgren8383e252019-05-27 04:51:56 -07001046 if (ddata->disable_on_idle)
1047 reset_control_deassert(ddata->rsts);
1048
Tony Lindgrenff437282019-03-21 11:00:21 -07001049 pdata = dev_get_platdata(ddata->dev);
1050 if (!pdata)
1051 return 0;
1052
1053 if (!pdata->enable_module)
1054 return -ENODEV;
1055
1056 error = pdata->enable_module(dev, &ddata->cookie);
1057 if (error)
1058 dev_err(dev, "%s: could not enable: %i\n",
1059 __func__, error);
1060
1061 return 0;
1062}
1063
1064static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1065{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001066 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001067 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001068
1069 ddata = dev_get_drvdata(dev);
1070
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001071 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001072 return 0;
1073
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001074 sysc_clkdm_deny_idle(ddata);
1075
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001076 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001077 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001078 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001079 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001080 } else {
1081 error = sysc_disable_module(dev);
1082 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001083 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001084 }
1085
Tony Lindgrend8789702019-03-21 11:00:21 -07001086 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001087
Tony Lindgrend8789702019-03-21 11:00:21 -07001088 if (sysc_opt_clks_needed(ddata))
1089 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001090
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001091 ddata->enabled = false;
1092
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001093err_allow_idle:
1094 sysc_clkdm_allow_idle(ddata);
1095
Tony Lindgren8383e252019-05-27 04:51:56 -07001096 if (ddata->disable_on_idle)
1097 reset_control_assert(ddata->rsts);
1098
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001099 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001100}
1101
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001102static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001103{
1104 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001105 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001106
1107 ddata = dev_get_drvdata(dev);
1108
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001109 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001110 return 0;
1111
Tony Lindgren8383e252019-05-27 04:51:56 -07001112 if (ddata->disable_on_idle)
1113 reset_control_deassert(ddata->rsts);
1114
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001115 sysc_clkdm_deny_idle(ddata);
1116
Tony Lindgrend8789702019-03-21 11:00:21 -07001117 if (sysc_opt_clks_needed(ddata)) {
1118 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001119 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001120 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001121 }
1122
Tony Lindgrend8789702019-03-21 11:00:21 -07001123 error = sysc_enable_main_clocks(ddata);
1124 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001125 goto err_opt_clocks;
1126
1127 if (ddata->legacy_mode) {
1128 error = sysc_runtime_resume_legacy(dev, ddata);
1129 if (error)
1130 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001131 } else {
1132 error = sysc_enable_module(dev);
1133 if (error)
1134 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001135 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001136
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001137 ddata->enabled = true;
1138
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001139 sysc_clkdm_allow_idle(ddata);
1140
Tony Lindgrend8789702019-03-21 11:00:21 -07001141 return 0;
1142
1143err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001144 sysc_disable_main_clocks(ddata);
1145err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001146 if (sysc_opt_clks_needed(ddata))
1147 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001148err_allow_idle:
1149 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001150
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001151 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001152}
1153
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001154static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001155{
1156 struct sysc *ddata;
1157
1158 ddata = dev_get_drvdata(dev);
1159
Tony Lindgren40d9f912018-09-24 12:16:54 -07001160 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001161 return 0;
1162
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001163 return pm_runtime_force_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001164}
1165
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001166static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001167{
1168 struct sysc *ddata;
1169
1170 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001171
Tony Lindgren40d9f912018-09-24 12:16:54 -07001172 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001173 return 0;
1174
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001175 return pm_runtime_force_resume(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001176}
1177
Tony Lindgren0eecc632017-10-10 14:23:43 -07001178static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001179 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001180 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1181 sysc_runtime_resume,
1182 NULL)
1183};
1184
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001185/* Module revision register based quirks */
1186struct sysc_revision_quirk {
1187 const char *name;
1188 u32 base;
1189 int rev_offset;
1190 int sysc_offset;
1191 int syss_offset;
1192 u32 revision;
1193 u32 revision_mask;
1194 u32 quirks;
1195};
1196
1197#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1198 optrev_val, optrevmask, optquirkmask) \
1199 { \
1200 .name = (optname), \
1201 .base = (optbase), \
1202 .rev_offset = (optrev), \
1203 .sysc_offset = (optsysc), \
1204 .syss_offset = (optsyss), \
1205 .revision = (optrev_val), \
1206 .revision_mask = (optrevmask), \
1207 .quirks = (optquirkmask), \
1208 }
1209
1210static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1211 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001212 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -07001213 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001214 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
1215 SYSC_QUIRK_LEGACY_IDLE),
1216 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff,
1217 SYSC_QUIRK_LEGACY_IDLE),
1218 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1219 SYSC_QUIRK_LEGACY_IDLE),
1220 SYSC_QUIRK("smartreflex", 0, -1, 0x24, -1, 0x00000000, 0xffffffff,
1221 SYSC_QUIRK_LEGACY_IDLE),
1222 SYSC_QUIRK("smartreflex", 0, -1, 0x38, -1, 0x00000000, 0xffffffff,
1223 SYSC_QUIRK_LEGACY_IDLE),
1224 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001225 0),
Tony Lindgren8cde5d52018-04-16 10:25:15 -07001226 /* Some timers on omap4 and later */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001227 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x50002100, 0xffffffff,
Tony Lindgren072167d2019-01-29 07:53:47 -08001228 0),
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001229 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x4fff1301, 0xffff00ff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001230 0),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001231 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1232 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001233 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001234 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001235 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001236 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001237 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001238 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001239 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001240
Tony Lindgrena54275f2019-03-21 11:00:21 -07001241 /* Quirks that need to be set based on the module address */
1242 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -1, 0x50000800, 0xffffffff,
1243 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1244 SYSC_QUIRK_SWSUP_SIDLE),
1245
Tony Lindgren4e23be42019-06-10 04:48:05 -07001246 /* Quirks that need to be set based on detected module */
1247 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
1248 SYSC_MODULE_QUIRK_HDQ1W),
1249 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
1250 SYSC_MODULE_QUIRK_HDQ1W),
1251 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
1252 SYSC_MODULE_QUIRK_I2C),
1253 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
1254 SYSC_MODULE_QUIRK_I2C),
1255 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
1256 SYSC_MODULE_QUIRK_I2C),
1257 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
1258 SYSC_MODULE_QUIRK_I2C),
1259 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1260 SYSC_MODULE_QUIRK_WDT),
1261
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001262#ifdef DEBUG
Tony Lindgren1ba30692018-09-24 12:17:05 -07001263 SYSC_QUIRK("adc", 0, 0, 0x10, -1, 0x47300001, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001264 SYSC_QUIRK("atl", 0, 0, -1, -1, 0x0a070100, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001265 SYSC_QUIRK("aess", 0, 0, 0x10, -1, 0x40000000, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001266 SYSC_QUIRK("cm", 0, 0, -1, -1, 0x40000301, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001267 SYSC_QUIRK("control", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001268 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001269 0xffff00f0, 0),
Tony Lindgren89bbc6f2019-07-22 03:44:42 -07001270 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0xa3170504, 0xffffffff, 0),
1271 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren13aad512019-03-21 11:00:21 -07001272 SYSC_QUIRK("dmic", 0, 0, 0x10, -1, 0x50010000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001273 SYSC_QUIRK("dwc3", 0, 0, 0x10, -1, 0x500a0200, 0xffffffff, 0),
1274 SYSC_QUIRK("epwmss", 0, 0, 0x4, -1, 0x47400001, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001275 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -1, 0, 0, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001276 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
1277 SYSC_QUIRK("iss", 0, 0, 0x10, -1, 0x40000101, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001278 SYSC_QUIRK("lcdc", 0, 0, 0x54, -1, 0x4f201000, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001279 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44306302, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001280 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44307b02, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001281 SYSC_QUIRK("mcbsp", 0, -1, 0x8c, -1, 0, 0, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001282 SYSC_QUIRK("mcspi", 0, 0, 0x10, -1, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001283 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001284 SYSC_QUIRK("mailbox", 0, 0, 0x10, -1, 0x00000400, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001285 SYSC_QUIRK("m3", 0, 0, -1, -1, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001286 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001287 SYSC_QUIRK("ocp2scp", 0, 0, -1, -1, 0x50060007, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001288 SYSC_QUIRK("padconf", 0, 0, 0x10, -1, 0x4fff0800, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001289 SYSC_QUIRK("padconf", 0, 0, -1, -1, 0x40001100, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001290 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000100, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001291 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x00004102, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001292 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000400, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001293 SYSC_QUIRK("scm", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001294 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4e8b0100, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001295 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4f000100, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001296 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001297 SYSC_QUIRK("scrm", 0, 0, -1, -1, 0x00000010, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001298 SYSC_QUIRK("sdio", 0, 0, 0x10, -1, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001299 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001300 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001301 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40000902, 0xffffffff, 0),
1302 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40002903, 0xffffffff, 0),
1303 SYSC_QUIRK("spinlock", 0, 0, 0x10, -1, 0x50020000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001304 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -1, 0x00000020, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001305 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -1, 0x4eb01908, 0xffff00f0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001306 SYSC_QUIRK("timer32k", 0, 0, 0x4, -1, 0x00000060, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001307 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001308 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001309 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001310 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -1, 0x50700101, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001311 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1312 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001313 SYSC_QUIRK("vfpe", 0, 0, 0x104, -1, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001314#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001315};
1316
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001317/*
1318 * Early quirks based on module base and register offsets only that are
1319 * needed before the module revision can be read
1320 */
1321static void sysc_init_early_quirks(struct sysc *ddata)
1322{
1323 const struct sysc_revision_quirk *q;
1324 int i;
1325
1326 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1327 q = &sysc_revision_quirks[i];
1328
1329 if (!q->base)
1330 continue;
1331
1332 if (q->base != ddata->module_pa)
1333 continue;
1334
1335 if (q->rev_offset >= 0 &&
1336 q->rev_offset != ddata->offsets[SYSC_REVISION])
1337 continue;
1338
1339 if (q->sysc_offset >= 0 &&
1340 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1341 continue;
1342
1343 if (q->syss_offset >= 0 &&
1344 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1345 continue;
1346
1347 ddata->name = q->name;
1348 ddata->cfg.quirks |= q->quirks;
1349 }
1350}
1351
1352/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001353static void sysc_init_revision_quirks(struct sysc *ddata)
1354{
1355 const struct sysc_revision_quirk *q;
1356 int i;
1357
1358 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1359 q = &sysc_revision_quirks[i];
1360
1361 if (q->base && q->base != ddata->module_pa)
1362 continue;
1363
1364 if (q->rev_offset >= 0 &&
1365 q->rev_offset != ddata->offsets[SYSC_REVISION])
1366 continue;
1367
1368 if (q->sysc_offset >= 0 &&
1369 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1370 continue;
1371
1372 if (q->syss_offset >= 0 &&
1373 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1374 continue;
1375
1376 if (q->revision == ddata->revision ||
1377 (q->revision & q->revision_mask) ==
1378 (ddata->revision & q->revision_mask)) {
1379 ddata->name = q->name;
1380 ddata->cfg.quirks |= q->quirks;
1381 }
1382 }
1383}
1384
Tony Lindgren4e23be42019-06-10 04:48:05 -07001385/* 1-wire needs module's internal clocks enabled for reset */
1386static void sysc_clk_enable_quirk_hdq1w(struct sysc *ddata)
1387{
1388 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1389 u16 val;
1390
1391 val = sysc_read(ddata, offset);
1392 val |= BIT(5);
1393 sysc_write(ddata, offset, val);
1394}
1395
1396/* I2C needs extra enable bit toggling for reset */
1397static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1398{
1399 int offset;
1400 u16 val;
1401
1402 /* I2C_CON, omap2/3 is different from omap4 and later */
1403 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1404 offset = 0x24;
1405 else
1406 offset = 0xa4;
1407
1408 /* I2C_EN */
1409 val = sysc_read(ddata, offset);
1410 if (enable)
1411 val |= BIT(15);
1412 else
1413 val &= ~BIT(15);
1414 sysc_write(ddata, offset, val);
1415}
1416
1417static void sysc_clk_enable_quirk_i2c(struct sysc *ddata)
1418{
1419 sysc_clk_quirk_i2c(ddata, true);
1420}
1421
1422static void sysc_clk_disable_quirk_i2c(struct sysc *ddata)
1423{
1424 sysc_clk_quirk_i2c(ddata, false);
1425}
1426
1427/* Watchdog timer needs a disable sequence after reset */
1428static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1429{
1430 int wps, spr, error;
1431 u32 val;
1432
1433 wps = 0x34;
1434 spr = 0x48;
1435
1436 sysc_write(ddata, spr, 0xaaaa);
1437 error = readl_poll_timeout(ddata->module_va + wps, val,
1438 !(val & 0x10), 100,
1439 MAX_MODULE_SOFTRESET_WAIT);
1440 if (error)
1441 dev_warn(ddata->dev, "wdt disable spr failed\n");
1442
1443 sysc_write(ddata, wps, 0x5555);
1444 error = readl_poll_timeout(ddata->module_va + wps, val,
1445 !(val & 0x10), 100,
1446 MAX_MODULE_SOFTRESET_WAIT);
1447 if (error)
1448 dev_warn(ddata->dev, "wdt disable wps failed\n");
1449}
1450
1451static void sysc_init_module_quirks(struct sysc *ddata)
1452{
1453 if (ddata->legacy_mode || !ddata->name)
1454 return;
1455
1456 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
1457 ddata->clk_enable_quirk = sysc_clk_enable_quirk_hdq1w;
1458
1459 return;
1460 }
1461
1462 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
1463 ddata->clk_enable_quirk = sysc_clk_enable_quirk_i2c;
1464 ddata->clk_disable_quirk = sysc_clk_disable_quirk_i2c;
1465
1466 return;
1467 }
1468
1469 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT)
1470 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
1471}
1472
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001473static int sysc_clockdomain_init(struct sysc *ddata)
1474{
1475 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1476 struct clk *fck = NULL, *ick = NULL;
1477 int error;
1478
1479 if (!pdata || !pdata->init_clockdomain)
1480 return 0;
1481
1482 switch (ddata->nr_clocks) {
1483 case 2:
1484 ick = ddata->clocks[SYSC_ICK];
1485 /* fallthrough */
1486 case 1:
1487 fck = ddata->clocks[SYSC_FCK];
1488 break;
1489 case 0:
1490 return 0;
1491 }
1492
1493 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
1494 if (!error || error == -ENODEV)
1495 return 0;
1496
1497 return error;
1498}
1499
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001500/*
1501 * Note that pdata->init_module() typically does a reset first. After
1502 * pdata->init_module() is done, PM runtime can be used for the interconnect
1503 * target module.
1504 */
1505static int sysc_legacy_init(struct sysc *ddata)
1506{
1507 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1508 int error;
1509
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001510 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001511 return 0;
1512
1513 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
1514 if (error == -EEXIST)
1515 error = 0;
1516
1517 return error;
1518}
1519
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001520/**
1521 * sysc_rstctrl_reset_deassert - deassert rstctrl reset
1522 * @ddata: device driver data
1523 * @reset: reset before deassert
1524 *
1525 * A module can have both OCP softreset control and external rstctrl.
1526 * If more complicated rstctrl resets are needed, please handle these
1527 * directly from the child device driver and map only the module reset
1528 * for the parent interconnect target module device.
1529 *
1530 * Automatic reset of the module on init can be skipped with the
1531 * "ti,no-reset-on-init" device tree property.
1532 */
1533static int sysc_rstctrl_reset_deassert(struct sysc *ddata, bool reset)
1534{
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001535 int error, val;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001536
1537 if (!ddata->rsts)
1538 return 0;
1539
1540 if (reset) {
1541 error = reset_control_assert(ddata->rsts);
1542 if (error)
1543 return error;
1544 }
1545
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001546 error = reset_control_deassert(ddata->rsts);
1547 if (error == -EEXIST)
1548 return 0;
1549
1550 error = readx_poll_timeout(reset_control_status, ddata->rsts, val,
1551 val == 0, 100, MAX_MODULE_SOFTRESET_WAIT);
1552
1553 return error;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001554}
1555
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001556/*
1557 * Note that the caller must ensure the interconnect target module is enabled
1558 * before calling reset. Otherwise reset will not complete.
1559 */
Faiz Abbas596e7952018-07-09 22:18:39 +05301560static int sysc_reset(struct sysc *ddata)
1561{
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001562 int sysc_offset, syss_offset, sysc_val, rstval, quirks, error = 0;
1563 u32 sysc_mask, syss_done;
Faiz Abbas596e7952018-07-09 22:18:39 +05301564
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001565 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
1566 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
1567 quirks = ddata->cfg.quirks;
1568
1569 if (ddata->legacy_mode || sysc_offset < 0 ||
1570 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05301571 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
1572 return 0;
1573
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001574 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05301575
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001576 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
1577 syss_done = 0;
1578 else
1579 syss_done = ddata->cfg.syss_mask;
1580
Tony Lindgren4e23be42019-06-10 04:48:05 -07001581 if (ddata->clk_disable_quirk)
1582 ddata->clk_disable_quirk(ddata);
1583
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001584 sysc_val = sysc_read_sysconfig(ddata);
1585 sysc_val |= sysc_mask;
1586 sysc_write(ddata, sysc_offset, sysc_val);
Faiz Abbas596e7952018-07-09 22:18:39 +05301587
Tony Lindgren4e23be42019-06-10 04:48:05 -07001588 if (ddata->clk_enable_quirk)
1589 ddata->clk_enable_quirk(ddata);
1590
Faiz Abbas596e7952018-07-09 22:18:39 +05301591 /* Poll on reset status */
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001592 if (syss_offset >= 0) {
1593 error = readx_poll_timeout(sysc_read_sysstatus, ddata, rstval,
1594 (rstval & ddata->cfg.syss_mask) ==
1595 syss_done,
1596 100, MAX_MODULE_SOFTRESET_WAIT);
Faiz Abbas596e7952018-07-09 22:18:39 +05301597
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001598 } else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS) {
1599 error = readx_poll_timeout(sysc_read_sysconfig, ddata, rstval,
1600 !(rstval & sysc_mask),
1601 100, MAX_MODULE_SOFTRESET_WAIT);
1602 }
1603
Tony Lindgren4e23be42019-06-10 04:48:05 -07001604 if (ddata->reset_done_quirk)
1605 ddata->reset_done_quirk(ddata);
1606
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001607 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05301608}
1609
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001610/*
1611 * At this point the module is configured enough to read the revision but
1612 * module may not be completely configured yet to use PM runtime. Enable
1613 * all clocks directly during init to configure the quirks needed for PM
1614 * runtime based on the revision register.
1615 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08001616static int sysc_init_module(struct sysc *ddata)
1617{
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001618 int error = 0;
1619 bool manage_clocks = true;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001620
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001621 error = sysc_rstctrl_reset_deassert(ddata, false);
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001622 if (error)
1623 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001624
Tony Lindgren386cb762019-03-22 07:49:30 -07001625 if (ddata->cfg.quirks &
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001626 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))
1627 manage_clocks = false;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001628
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001629 error = sysc_clockdomain_init(ddata);
1630 if (error)
1631 return error;
1632
Tony Lindgrend0989132019-09-05 07:37:22 -07001633 sysc_clkdm_deny_idle(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001634
Tony Lindgrend0989132019-09-05 07:37:22 -07001635 /*
1636 * Always enable clocks. The bootloader may or may not have enabled
1637 * the related clocks.
1638 */
1639 error = sysc_enable_opt_clocks(ddata);
1640 if (error)
1641 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001642
Tony Lindgrend0989132019-09-05 07:37:22 -07001643 error = sysc_enable_main_clocks(ddata);
1644 if (error)
1645 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05301646
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001647 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
1648 error = sysc_rstctrl_reset_deassert(ddata, true);
1649 if (error)
1650 goto err_main_clocks;
1651 }
1652
Tony Lindgren566a9b052017-12-15 09:41:19 -08001653 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001654 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001655 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001656
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001657 if (ddata->legacy_mode) {
1658 error = sysc_legacy_init(ddata);
1659 if (error)
1660 goto err_main_clocks;
1661 }
1662
Tony Lindgrend0989132019-09-05 07:37:22 -07001663 if (!ddata->legacy_mode) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001664 error = sysc_enable_module(ddata->dev);
1665 if (error)
1666 goto err_main_clocks;
1667 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001668
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001669 error = sysc_reset(ddata);
1670 if (error)
1671 dev_err(ddata->dev, "Reset failed with %d\n", error);
1672
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001673 if (!ddata->legacy_mode && manage_clocks)
1674 sysc_disable_module(ddata->dev);
1675
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001676err_main_clocks:
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001677 if (manage_clocks)
1678 sysc_disable_main_clocks(ddata);
1679err_opt_clocks:
Tony Lindgrend0989132019-09-05 07:37:22 -07001680 /* No re-enable of clockdomain autoidle to prevent module autoidle */
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001681 if (manage_clocks) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001682 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001683 sysc_clkdm_allow_idle(ddata);
1684 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001685
1686 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001687}
1688
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001689static int sysc_init_sysc_mask(struct sysc *ddata)
1690{
1691 struct device_node *np = ddata->dev->of_node;
1692 int error;
1693 u32 val;
1694
1695 error = of_property_read_u32(np, "ti,sysc-mask", &val);
1696 if (error)
1697 return 0;
1698
Tony Lindgrene212abd2019-07-22 03:44:52 -07001699 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001700
1701 return 0;
1702}
1703
1704static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
1705 const char *name)
1706{
1707 struct device_node *np = ddata->dev->of_node;
1708 struct property *prop;
1709 const __be32 *p;
1710 u32 val;
1711
1712 of_property_for_each_u32(np, name, prop, p, val) {
1713 if (val >= SYSC_NR_IDLEMODES) {
1714 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
1715 return -EINVAL;
1716 }
1717 *idlemodes |= (1 << val);
1718 }
1719
1720 return 0;
1721}
1722
1723static int sysc_init_idlemodes(struct sysc *ddata)
1724{
1725 int error;
1726
1727 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
1728 "ti,sysc-midle");
1729 if (error)
1730 return error;
1731
1732 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
1733 "ti,sysc-sidle");
1734 if (error)
1735 return error;
1736
1737 return 0;
1738}
1739
1740/*
1741 * Only some devices on omap4 and later have SYSCONFIG reset done
1742 * bit. We can detect this if there is no SYSSTATUS at all, or the
1743 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
1744 * have multiple bits for the child devices like OHCI and EHCI.
1745 * Depends on SYSC being parsed first.
1746 */
1747static int sysc_init_syss_mask(struct sysc *ddata)
1748{
1749 struct device_node *np = ddata->dev->of_node;
1750 int error;
1751 u32 val;
1752
1753 error = of_property_read_u32(np, "ti,syss-mask", &val);
1754 if (error) {
1755 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
1756 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
1757 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1758 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1759
1760 return 0;
1761 }
1762
1763 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1764 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1765
1766 ddata->cfg.syss_mask = val;
1767
1768 return 0;
1769}
1770
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001771/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001772 * Many child device drivers need to have fck and opt clocks available
1773 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001774 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001775static int sysc_child_add_named_clock(struct sysc *ddata,
1776 struct device *child,
1777 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001778{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001779 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001780 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001781 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001782
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001783 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001784 return 0;
1785
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001786 clk = clk_get(child, name);
1787 if (!IS_ERR(clk)) {
1788 clk_put(clk);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001789
1790 return -EEXIST;
1791 }
1792
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001793 clk = clk_get(ddata->dev, name);
1794 if (IS_ERR(clk))
1795 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001796
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001797 l = clkdev_create(clk, name, dev_name(child));
1798 if (!l)
1799 error = -ENOMEM;
1800
1801 clk_put(clk);
1802
1803 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001804}
1805
Tony Lindgren09dfe582018-04-16 10:25:52 -07001806static int sysc_child_add_clocks(struct sysc *ddata,
1807 struct device *child)
1808{
1809 int i, error;
1810
1811 for (i = 0; i < ddata->nr_clocks; i++) {
1812 error = sysc_child_add_named_clock(ddata,
1813 child,
1814 ddata->clock_roles[i]);
1815 if (error && error != -EEXIST) {
1816 dev_err(ddata->dev, "could not add child clock %s: %i\n",
1817 ddata->clock_roles[i], error);
1818
1819 return error;
1820 }
1821 }
1822
1823 return 0;
1824}
1825
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001826static struct device_type sysc_device_type = {
1827};
1828
1829static struct sysc *sysc_child_to_parent(struct device *dev)
1830{
1831 struct device *parent = dev->parent;
1832
1833 if (!parent || parent->type != &sysc_device_type)
1834 return NULL;
1835
1836 return dev_get_drvdata(parent);
1837}
1838
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001839static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
1840{
1841 struct sysc *ddata;
1842 int error;
1843
1844 ddata = sysc_child_to_parent(dev);
1845
1846 error = pm_generic_runtime_suspend(dev);
1847 if (error)
1848 return error;
1849
1850 if (!ddata->enabled)
1851 return 0;
1852
1853 return sysc_runtime_suspend(ddata->dev);
1854}
1855
1856static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
1857{
1858 struct sysc *ddata;
1859 int error;
1860
1861 ddata = sysc_child_to_parent(dev);
1862
1863 if (!ddata->enabled) {
1864 error = sysc_runtime_resume(ddata->dev);
1865 if (error < 0)
1866 dev_err(ddata->dev,
1867 "%s error: %i\n", __func__, error);
1868 }
1869
1870 return pm_generic_runtime_resume(dev);
1871}
1872
1873#ifdef CONFIG_PM_SLEEP
1874static int sysc_child_suspend_noirq(struct device *dev)
1875{
1876 struct sysc *ddata;
1877 int error;
1878
1879 ddata = sysc_child_to_parent(dev);
1880
Tony Lindgrenef55f822018-04-16 10:27:15 -07001881 dev_dbg(ddata->dev, "%s %s\n", __func__,
1882 ddata->name ? ddata->name : "");
1883
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001884 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001885 if (error) {
1886 dev_err(dev, "%s error at %i: %i\n",
1887 __func__, __LINE__, error);
1888
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001889 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001890 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001891
1892 if (!pm_runtime_status_suspended(dev)) {
1893 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001894 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07001895 dev_dbg(dev, "%s busy at %i: %i\n",
1896 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001897
Tony Lindgren4f3530f2018-08-08 01:07:06 -07001898 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001899 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001900
1901 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001902 if (error) {
1903 dev_err(dev, "%s error at %i: %i\n",
1904 __func__, __LINE__, error);
1905
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001906 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001907 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001908
1909 ddata->child_needs_resume = true;
1910 }
1911
1912 return 0;
1913}
1914
1915static int sysc_child_resume_noirq(struct device *dev)
1916{
1917 struct sysc *ddata;
1918 int error;
1919
1920 ddata = sysc_child_to_parent(dev);
1921
Tony Lindgrenef55f822018-04-16 10:27:15 -07001922 dev_dbg(ddata->dev, "%s %s\n", __func__,
1923 ddata->name ? ddata->name : "");
1924
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001925 if (ddata->child_needs_resume) {
1926 ddata->child_needs_resume = false;
1927
1928 error = sysc_runtime_resume(ddata->dev);
1929 if (error)
1930 dev_err(ddata->dev,
1931 "%s runtime resume error: %i\n",
1932 __func__, error);
1933
1934 error = pm_generic_runtime_resume(dev);
1935 if (error)
1936 dev_err(ddata->dev,
1937 "%s generic runtime resume: %i\n",
1938 __func__, error);
1939 }
1940
1941 return pm_generic_resume_noirq(dev);
1942}
1943#endif
1944
Tony Lindgrenb7182b42019-03-21 11:00:21 -07001945static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001946 .ops = {
1947 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
1948 sysc_child_runtime_resume,
1949 NULL)
1950 USE_PLATFORM_PM_SLEEP_OPS
1951 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
1952 sysc_child_resume_noirq)
1953 }
1954};
1955
1956/**
1957 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
1958 * @ddata: device driver data
1959 * @child: child device driver
1960 *
1961 * Allow idle for child devices as done with _od_runtime_suspend().
1962 * Otherwise many child devices will not idle because of the permanent
1963 * parent usecount set in pm_runtime_irq_safe().
1964 *
1965 * Note that the long term solution is to just modify the child device
1966 * drivers to not set pm_runtime_irq_safe() and then this can be just
1967 * dropped.
1968 */
1969static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
1970{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001971 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
1972 dev_pm_domain_set(child, &sysc_child_pm_domain);
1973}
1974
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001975static int sysc_notifier_call(struct notifier_block *nb,
1976 unsigned long event, void *device)
1977{
1978 struct device *dev = device;
1979 struct sysc *ddata;
1980 int error;
1981
1982 ddata = sysc_child_to_parent(dev);
1983 if (!ddata)
1984 return NOTIFY_DONE;
1985
1986 switch (event) {
1987 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07001988 error = sysc_child_add_clocks(ddata, dev);
1989 if (error)
1990 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001991 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001992 break;
1993 default:
1994 break;
1995 }
1996
1997 return NOTIFY_DONE;
1998}
1999
2000static struct notifier_block sysc_nb = {
2001 .notifier_call = sysc_notifier_call,
2002};
2003
Tony Lindgren566a9b052017-12-15 09:41:19 -08002004/* Device tree configured quirks */
2005struct sysc_dts_quirk {
2006 const char *name;
2007 u32 mask;
2008};
2009
2010static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2011 { .name = "ti,no-idle-on-init",
2012 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2013 { .name = "ti,no-reset-on-init",
2014 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002015 { .name = "ti,no-idle",
2016 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002017};
2018
Tony Lindgren4014c082018-12-10 14:11:26 -08002019static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2020 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002021{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002022 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002023 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002024
2025 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002026 const char *name = sysc_dts_quirks[i].name;
2027
2028 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002029 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002030 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002031
2032 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002033 if (is_child) {
2034 dev_warn(ddata->dev,
2035 "dts flag should be at module level for %s\n",
2036 name);
2037 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002038 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002039}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002040
Tony Lindgren4014c082018-12-10 14:11:26 -08002041static int sysc_init_dts_quirks(struct sysc *ddata)
2042{
2043 struct device_node *np = ddata->dev->of_node;
2044 int error;
2045 u32 val;
2046
2047 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2048
2049 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002050 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2051 if (!error) {
2052 if (val > 255) {
2053 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2054 val);
2055 }
2056
2057 ddata->cfg.srst_udelay = (u8)val;
2058 }
2059
2060 return 0;
2061}
2062
Tony Lindgren0eecc632017-10-10 14:23:43 -07002063static void sysc_unprepare(struct sysc *ddata)
2064{
2065 int i;
2066
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002067 if (!ddata->clocks)
2068 return;
2069
Tony Lindgren0eecc632017-10-10 14:23:43 -07002070 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2071 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2072 clk_unprepare(ddata->clocks[i]);
2073 }
2074}
2075
Tony Lindgren70a65242017-12-15 09:41:09 -08002076/*
2077 * Common sysc register bits found on omap2, also known as type1
2078 */
2079static const struct sysc_regbits sysc_regbits_omap2 = {
2080 .dmadisable_shift = -ENODEV,
2081 .midle_shift = 12,
2082 .sidle_shift = 3,
2083 .clkact_shift = 8,
2084 .emufree_shift = 5,
2085 .enwkup_shift = 2,
2086 .srst_shift = 1,
2087 .autoidle_shift = 0,
2088};
2089
2090static const struct sysc_capabilities sysc_omap2 = {
2091 .type = TI_SYSC_OMAP2,
2092 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2093 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2094 SYSC_OMAP2_AUTOIDLE,
2095 .regbits = &sysc_regbits_omap2,
2096};
2097
2098/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2099static const struct sysc_capabilities sysc_omap2_timer = {
2100 .type = TI_SYSC_OMAP2_TIMER,
2101 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2102 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2103 SYSC_OMAP2_AUTOIDLE,
2104 .regbits = &sysc_regbits_omap2,
2105 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2106};
2107
2108/*
2109 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2110 * with different sidle position
2111 */
2112static const struct sysc_regbits sysc_regbits_omap3_sham = {
2113 .dmadisable_shift = -ENODEV,
2114 .midle_shift = -ENODEV,
2115 .sidle_shift = 4,
2116 .clkact_shift = -ENODEV,
2117 .enwkup_shift = -ENODEV,
2118 .srst_shift = 1,
2119 .autoidle_shift = 0,
2120 .emufree_shift = -ENODEV,
2121};
2122
2123static const struct sysc_capabilities sysc_omap3_sham = {
2124 .type = TI_SYSC_OMAP3_SHAM,
2125 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2126 .regbits = &sysc_regbits_omap3_sham,
2127};
2128
2129/*
2130 * AES register bits found on omap3 and later, a variant of
2131 * sysc_regbits_omap2 with different sidle position
2132 */
2133static const struct sysc_regbits sysc_regbits_omap3_aes = {
2134 .dmadisable_shift = -ENODEV,
2135 .midle_shift = -ENODEV,
2136 .sidle_shift = 6,
2137 .clkact_shift = -ENODEV,
2138 .enwkup_shift = -ENODEV,
2139 .srst_shift = 1,
2140 .autoidle_shift = 0,
2141 .emufree_shift = -ENODEV,
2142};
2143
2144static const struct sysc_capabilities sysc_omap3_aes = {
2145 .type = TI_SYSC_OMAP3_AES,
2146 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2147 .regbits = &sysc_regbits_omap3_aes,
2148};
2149
2150/*
2151 * Common sysc register bits found on omap4, also known as type2
2152 */
2153static const struct sysc_regbits sysc_regbits_omap4 = {
2154 .dmadisable_shift = 16,
2155 .midle_shift = 4,
2156 .sidle_shift = 2,
2157 .clkact_shift = -ENODEV,
2158 .enwkup_shift = -ENODEV,
2159 .emufree_shift = 1,
2160 .srst_shift = 0,
2161 .autoidle_shift = -ENODEV,
2162};
2163
2164static const struct sysc_capabilities sysc_omap4 = {
2165 .type = TI_SYSC_OMAP4,
2166 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2167 SYSC_OMAP4_SOFTRESET,
2168 .regbits = &sysc_regbits_omap4,
2169};
2170
2171static const struct sysc_capabilities sysc_omap4_timer = {
2172 .type = TI_SYSC_OMAP4_TIMER,
2173 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2174 SYSC_OMAP4_SOFTRESET,
2175 .regbits = &sysc_regbits_omap4,
2176};
2177
2178/*
2179 * Common sysc register bits found on omap4, also known as type3
2180 */
2181static const struct sysc_regbits sysc_regbits_omap4_simple = {
2182 .dmadisable_shift = -ENODEV,
2183 .midle_shift = 2,
2184 .sidle_shift = 0,
2185 .clkact_shift = -ENODEV,
2186 .enwkup_shift = -ENODEV,
2187 .srst_shift = -ENODEV,
2188 .emufree_shift = -ENODEV,
2189 .autoidle_shift = -ENODEV,
2190};
2191
2192static const struct sysc_capabilities sysc_omap4_simple = {
2193 .type = TI_SYSC_OMAP4_SIMPLE,
2194 .regbits = &sysc_regbits_omap4_simple,
2195};
2196
2197/*
2198 * SmartReflex sysc found on omap34xx
2199 */
2200static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2201 .dmadisable_shift = -ENODEV,
2202 .midle_shift = -ENODEV,
2203 .sidle_shift = -ENODEV,
2204 .clkact_shift = 20,
2205 .enwkup_shift = -ENODEV,
2206 .srst_shift = -ENODEV,
2207 .emufree_shift = -ENODEV,
2208 .autoidle_shift = -ENODEV,
2209};
2210
2211static const struct sysc_capabilities sysc_34xx_sr = {
2212 .type = TI_SYSC_OMAP34XX_SR,
2213 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2214 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002215 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2216 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002217};
2218
2219/*
2220 * SmartReflex sysc found on omap36xx and later
2221 */
2222static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2223 .dmadisable_shift = -ENODEV,
2224 .midle_shift = -ENODEV,
2225 .sidle_shift = 24,
2226 .clkact_shift = -ENODEV,
2227 .enwkup_shift = 26,
2228 .srst_shift = -ENODEV,
2229 .emufree_shift = -ENODEV,
2230 .autoidle_shift = -ENODEV,
2231};
2232
2233static const struct sysc_capabilities sysc_36xx_sr = {
2234 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002235 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002236 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002237 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002238};
2239
2240static const struct sysc_capabilities sysc_omap4_sr = {
2241 .type = TI_SYSC_OMAP4_SR,
2242 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002243 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002244};
2245
2246/*
2247 * McASP register bits found on omap4 and later
2248 */
2249static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2250 .dmadisable_shift = -ENODEV,
2251 .midle_shift = -ENODEV,
2252 .sidle_shift = 0,
2253 .clkact_shift = -ENODEV,
2254 .enwkup_shift = -ENODEV,
2255 .srst_shift = -ENODEV,
2256 .emufree_shift = -ENODEV,
2257 .autoidle_shift = -ENODEV,
2258};
2259
2260static const struct sysc_capabilities sysc_omap4_mcasp = {
2261 .type = TI_SYSC_OMAP4_MCASP,
2262 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002263 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2264};
2265
2266/*
2267 * McASP found on dra7 and later
2268 */
2269static const struct sysc_capabilities sysc_dra7_mcasp = {
2270 .type = TI_SYSC_OMAP4_SIMPLE,
2271 .regbits = &sysc_regbits_omap4_simple,
2272 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002273};
2274
2275/*
2276 * FS USB host found on omap4 and later
2277 */
2278static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2279 .dmadisable_shift = -ENODEV,
2280 .midle_shift = -ENODEV,
2281 .sidle_shift = 24,
2282 .clkact_shift = -ENODEV,
2283 .enwkup_shift = 26,
2284 .srst_shift = -ENODEV,
2285 .emufree_shift = -ENODEV,
2286 .autoidle_shift = -ENODEV,
2287};
2288
2289static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2290 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2291 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2292 .regbits = &sysc_regbits_omap4_usb_host_fs,
2293};
2294
Faiz Abbas7f35e632018-07-09 22:18:38 +05302295static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2296 .dmadisable_shift = -ENODEV,
2297 .midle_shift = -ENODEV,
2298 .sidle_shift = -ENODEV,
2299 .clkact_shift = -ENODEV,
2300 .enwkup_shift = 4,
2301 .srst_shift = 0,
2302 .emufree_shift = -ENODEV,
2303 .autoidle_shift = -ENODEV,
2304};
2305
2306static const struct sysc_capabilities sysc_dra7_mcan = {
2307 .type = TI_SYSC_DRA7_MCAN,
2308 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2309 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002310 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302311};
2312
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002313static int sysc_init_pdata(struct sysc *ddata)
2314{
2315 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002316 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002317
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002318 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002319 return 0;
2320
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002321 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2322 if (!mdata)
2323 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002324
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002325 if (ddata->legacy_mode) {
2326 mdata->name = ddata->legacy_mode;
2327 mdata->module_pa = ddata->module_pa;
2328 mdata->module_size = ddata->module_size;
2329 mdata->offsets = ddata->offsets;
2330 mdata->nr_offsets = SYSC_MAX_REGS;
2331 mdata->cap = ddata->cap;
2332 mdata->cfg = &ddata->cfg;
2333 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002334
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002335 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002336
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002337 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002338}
2339
Tony Lindgren70a65242017-12-15 09:41:09 -08002340static int sysc_init_match(struct sysc *ddata)
2341{
2342 const struct sysc_capabilities *cap;
2343
2344 cap = of_device_get_match_data(ddata->dev);
2345 if (!cap)
2346 return -EINVAL;
2347
2348 ddata->cap = cap;
2349 if (ddata->cap)
2350 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2351
2352 return 0;
2353}
2354
Tony Lindgren76f0f772018-02-23 08:28:45 -08002355static void ti_sysc_idle(struct work_struct *work)
2356{
2357 struct sysc *ddata;
2358
2359 ddata = container_of(work, struct sysc, idle_work.work);
2360
Tony Lindgrend0989132019-09-05 07:37:22 -07002361 /*
2362 * One time decrement of clock usage counts if left on from init.
2363 * Note that we disable opt clocks unconditionally in this case
2364 * as they are enabled unconditionally during init without
2365 * considering sysc_opt_clks_needed() at that point.
2366 */
2367 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2368 SYSC_QUIRK_NO_IDLE_ON_INIT)) {
2369 sysc_clkdm_deny_idle(ddata);
2370 sysc_disable_main_clocks(ddata);
2371 sysc_disable_opt_clocks(ddata);
2372 sysc_clkdm_allow_idle(ddata);
2373 }
2374
2375 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
2376 if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE)
2377 return;
2378
2379 /*
2380 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
2381 * and SYSC_QUIRK_NO_RESET_ON_INIT
2382 */
Tony Lindgren76f0f772018-02-23 08:28:45 -08002383 if (pm_runtime_active(ddata->dev))
2384 pm_runtime_put_sync(ddata->dev);
2385}
2386
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002387static const struct of_device_id sysc_match_table[] = {
2388 { .compatible = "simple-bus", },
2389 { /* sentinel */ },
2390};
2391
Tony Lindgren0eecc632017-10-10 14:23:43 -07002392static int sysc_probe(struct platform_device *pdev)
2393{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002394 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002395 struct sysc *ddata;
2396 int error;
2397
2398 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
2399 if (!ddata)
2400 return -ENOMEM;
2401
2402 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002403 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002404
Tony Lindgren70a65242017-12-15 09:41:09 -08002405 error = sysc_init_match(ddata);
2406 if (error)
2407 return error;
2408
Tony Lindgren566a9b052017-12-15 09:41:19 -08002409 error = sysc_init_dts_quirks(ddata);
2410 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002411 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002412
Tony Lindgren0eecc632017-10-10 14:23:43 -07002413 error = sysc_map_and_check_registers(ddata);
2414 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002415 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07002416
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002417 error = sysc_init_sysc_mask(ddata);
2418 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002419 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002420
2421 error = sysc_init_idlemodes(ddata);
2422 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002423 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002424
2425 error = sysc_init_syss_mask(ddata);
2426 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002427 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002428
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002429 error = sysc_init_pdata(ddata);
2430 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002431 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002432
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07002433 sysc_init_early_quirks(ddata);
2434
2435 error = sysc_get_clocks(ddata);
2436 if (error)
2437 return error;
2438
Tony Lindgren50622362018-04-16 10:20:27 -07002439 error = sysc_init_resets(ddata);
2440 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002441 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002442
2443 error = sysc_init_module(ddata);
2444 if (error)
2445 goto unprepare;
2446
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002447 pm_runtime_enable(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002448 error = pm_runtime_get_sync(ddata->dev);
2449 if (error < 0) {
2450 pm_runtime_put_noidle(ddata->dev);
2451 pm_runtime_disable(ddata->dev);
2452 goto unprepare;
2453 }
2454
Tony Lindgren0eecc632017-10-10 14:23:43 -07002455 sysc_show_registers(ddata);
2456
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002457 ddata->dev->type = &sysc_device_type;
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002458 error = of_platform_populate(ddata->dev->of_node, sysc_match_table,
2459 pdata ? pdata->auxdata : NULL,
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002460 ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002461 if (error)
2462 goto err;
2463
Tony Lindgren76f0f772018-02-23 08:28:45 -08002464 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
2465
2466 /* At least earlycon won't survive without deferred idle */
Tony Lindgrend0989132019-09-05 07:37:22 -07002467 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2468 SYSC_QUIRK_NO_IDLE_ON_INIT |
Tony Lindgren76f0f772018-02-23 08:28:45 -08002469 SYSC_QUIRK_NO_RESET_ON_INIT)) {
2470 schedule_delayed_work(&ddata->idle_work, 3000);
2471 } else {
2472 pm_runtime_put(&pdev->dev);
2473 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07002474
Tony Lindgren50622362018-04-16 10:20:27 -07002475 if (!of_get_available_child_count(ddata->dev->of_node))
Tony Lindgren8383e252019-05-27 04:51:56 -07002476 ddata->disable_on_idle = true;
Tony Lindgren50622362018-04-16 10:20:27 -07002477
Tony Lindgren0eecc632017-10-10 14:23:43 -07002478 return 0;
2479
2480err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07002481 pm_runtime_put_sync(&pdev->dev);
2482 pm_runtime_disable(&pdev->dev);
2483unprepare:
2484 sysc_unprepare(ddata);
2485
2486 return error;
2487}
2488
Tony Lindgren684be5a2017-10-13 10:48:40 -07002489static int sysc_remove(struct platform_device *pdev)
2490{
2491 struct sysc *ddata = platform_get_drvdata(pdev);
2492 int error;
2493
Tony Lindgren76f0f772018-02-23 08:28:45 -08002494 cancel_delayed_work_sync(&ddata->idle_work);
2495
Tony Lindgren684be5a2017-10-13 10:48:40 -07002496 error = pm_runtime_get_sync(ddata->dev);
2497 if (error < 0) {
2498 pm_runtime_put_noidle(ddata->dev);
2499 pm_runtime_disable(ddata->dev);
2500 goto unprepare;
2501 }
2502
2503 of_platform_depopulate(&pdev->dev);
2504
Tony Lindgren684be5a2017-10-13 10:48:40 -07002505 pm_runtime_put_sync(&pdev->dev);
2506 pm_runtime_disable(&pdev->dev);
Tony Lindgren50622362018-04-16 10:20:27 -07002507 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07002508
2509unprepare:
2510 sysc_unprepare(ddata);
2511
2512 return 0;
2513}
2514
Tony Lindgren0eecc632017-10-10 14:23:43 -07002515static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08002516 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
2517 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
2518 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
2519 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
2520 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
2521 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
2522 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
2523 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
2524 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
2525 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
2526 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08002527 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08002528 { .compatible = "ti,sysc-usb-host-fs",
2529 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05302530 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07002531 { },
2532};
2533MODULE_DEVICE_TABLE(of, sysc_match);
2534
2535static struct platform_driver sysc_driver = {
2536 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07002537 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07002538 .driver = {
2539 .name = "ti-sysc",
2540 .of_match_table = sysc_match,
2541 .pm = &sysc_pm_ops,
2542 },
2543};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002544
2545static int __init sysc_init(void)
2546{
2547 bus_register_notifier(&platform_bus_type, &sysc_nb);
2548
2549 return platform_driver_register(&sysc_driver);
2550}
2551module_init(sysc_init);
2552
2553static void __exit sysc_exit(void)
2554{
2555 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
2556 platform_driver_unregister(&sysc_driver);
2557}
2558module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002559
2560MODULE_DESCRIPTION("TI sysc interconnect target driver");
2561MODULE_LICENSE("GPL v2");