blob: 24583d82b5840d7ae5ab20bf428c14d2616f6620 [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])) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700283 dev_err(ddata->dev, "clock get error for %s: %li\n",
284 name, PTR_ERR(ddata->clocks[index]));
285
286 return PTR_ERR(ddata->clocks[index]);
287 }
288
289 error = clk_prepare(ddata->clocks[index]);
290 if (error) {
291 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
292 name, error);
293
294 return error;
295 }
296
297 return 0;
298}
299
300static int sysc_get_clocks(struct sysc *ddata)
301{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700302 struct device_node *np = ddata->dev->of_node;
303 struct property *prop;
304 const char *name;
305 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700306
Kees Cook20749052018-06-18 10:45:49 -0700307 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700308 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700309 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700310 GFP_KERNEL);
311 if (!ddata->clock_roles)
312 return -ENOMEM;
313
314 of_property_for_each_string(np, "clock-names", prop, name) {
315 if (!strncmp(clock_names[SYSC_FCK], name, 3))
316 nr_fck++;
317 if (!strncmp(clock_names[SYSC_ICK], name, 3))
318 nr_ick++;
319 ddata->clock_roles[ddata->nr_clocks] = name;
320 ddata->nr_clocks++;
321 }
322
323 if (ddata->nr_clocks < 1)
324 return 0;
325
Tony Lindgrena54275f2019-03-21 11:00:21 -0700326 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
327 error = sysc_init_ext_opt_clock(ddata, NULL);
328 if (error)
329 return error;
330 }
331
Tony Lindgren09dfe582018-04-16 10:25:52 -0700332 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
333 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
334
335 return -EINVAL;
336 }
337
338 if (nr_fck > 1 || nr_ick > 1) {
339 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
340
341 return -EINVAL;
342 }
343
Kees Cook20749052018-06-18 10:45:49 -0700344 ddata->clocks = devm_kcalloc(ddata->dev,
345 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700346 GFP_KERNEL);
347 if (!ddata->clocks)
348 return -ENOMEM;
349
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800350 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
351 const char *name = ddata->clock_roles[i];
352
353 if (!name)
354 continue;
355
356 error = sysc_get_one_clock(ddata, name);
Tony Lindgren2783d062019-09-05 13:01:29 -0700357 if (error)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700358 return error;
359 }
360
361 return 0;
362}
363
Tony Lindgrend8789702019-03-21 11:00:21 -0700364static int sysc_enable_main_clocks(struct sysc *ddata)
365{
366 struct clk *clock;
367 int i, error;
368
369 if (!ddata->clocks)
370 return 0;
371
372 for (i = 0; i < SYSC_OPTFCK0; i++) {
373 clock = ddata->clocks[i];
374
375 /* Main clocks may not have ick */
376 if (IS_ERR_OR_NULL(clock))
377 continue;
378
379 error = clk_enable(clock);
380 if (error)
381 goto err_disable;
382 }
383
384 return 0;
385
386err_disable:
387 for (i--; i >= 0; i--) {
388 clock = ddata->clocks[i];
389
390 /* Main clocks may not have ick */
391 if (IS_ERR_OR_NULL(clock))
392 continue;
393
394 clk_disable(clock);
395 }
396
397 return error;
398}
399
400static void sysc_disable_main_clocks(struct sysc *ddata)
401{
402 struct clk *clock;
403 int i;
404
405 if (!ddata->clocks)
406 return;
407
408 for (i = 0; i < SYSC_OPTFCK0; i++) {
409 clock = ddata->clocks[i];
410 if (IS_ERR_OR_NULL(clock))
411 continue;
412
413 clk_disable(clock);
414 }
415}
416
417static int sysc_enable_opt_clocks(struct sysc *ddata)
418{
419 struct clk *clock;
420 int i, error;
421
422 if (!ddata->clocks)
423 return 0;
424
425 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
426 clock = ddata->clocks[i];
427
428 /* Assume no holes for opt clocks */
429 if (IS_ERR_OR_NULL(clock))
430 return 0;
431
432 error = clk_enable(clock);
433 if (error)
434 goto err_disable;
435 }
436
437 return 0;
438
439err_disable:
440 for (i--; i >= 0; i--) {
441 clock = ddata->clocks[i];
442 if (IS_ERR_OR_NULL(clock))
443 continue;
444
445 clk_disable(clock);
446 }
447
448 return error;
449}
450
451static void sysc_disable_opt_clocks(struct sysc *ddata)
452{
453 struct clk *clock;
454 int i;
455
456 if (!ddata->clocks)
457 return;
458
459 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
460 clock = ddata->clocks[i];
461
462 /* Assume no holes for opt clocks */
463 if (IS_ERR_OR_NULL(clock))
464 return;
465
466 clk_disable(clock);
467 }
468}
469
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700470static void sysc_clkdm_deny_idle(struct sysc *ddata)
471{
472 struct ti_sysc_platform_data *pdata;
473
474 if (ddata->legacy_mode)
475 return;
476
477 pdata = dev_get_platdata(ddata->dev);
478 if (pdata && pdata->clkdm_deny_idle)
479 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
480}
481
482static void sysc_clkdm_allow_idle(struct sysc *ddata)
483{
484 struct ti_sysc_platform_data *pdata;
485
486 if (ddata->legacy_mode)
487 return;
488
489 pdata = dev_get_platdata(ddata->dev);
490 if (pdata && pdata->clkdm_allow_idle)
491 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
492}
493
Tony Lindgren0eecc632017-10-10 14:23:43 -0700494/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700495 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700496 * @ddata: device driver data
497 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700498 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700499 */
500static int sysc_init_resets(struct sysc *ddata)
501{
Tony Lindgren50622362018-04-16 10:20:27 -0700502 ddata->rsts =
Tony Lindgrenea5a2e42019-05-27 04:51:56 -0700503 devm_reset_control_get_optional(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700504 if (IS_ERR(ddata->rsts))
505 return PTR_ERR(ddata->rsts);
506
Tony Lindgren50622362018-04-16 10:20:27 -0700507 return 0;
508}
509
510/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700511 * sysc_parse_and_check_child_range - parses module IO region from ranges
512 * @ddata: device driver data
513 *
514 * In general we only need rev, syss, and sysc registers and not the whole
515 * module range. But we do want the offsets for these registers from the
516 * module base. This allows us to check them against the legacy hwmod
517 * platform data. Let's also check the ranges are configured properly.
518 */
519static int sysc_parse_and_check_child_range(struct sysc *ddata)
520{
521 struct device_node *np = ddata->dev->of_node;
522 const __be32 *ranges;
523 u32 nr_addr, nr_size;
524 int len, error;
525
526 ranges = of_get_property(np, "ranges", &len);
527 if (!ranges) {
528 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
529
530 return -ENOENT;
531 }
532
533 len /= sizeof(*ranges);
534
535 if (len < 3) {
536 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
537
538 return -EINVAL;
539 }
540
541 error = of_property_read_u32(np, "#address-cells", &nr_addr);
542 if (error)
543 return -ENOENT;
544
545 error = of_property_read_u32(np, "#size-cells", &nr_size);
546 if (error)
547 return -ENOENT;
548
549 if (nr_addr != 1 || nr_size != 1) {
550 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
551
552 return -EINVAL;
553 }
554
555 ranges++;
556 ddata->module_pa = of_translate_address(np, ranges++);
557 ddata->module_size = be32_to_cpup(ranges);
558
Tony Lindgren0eecc632017-10-10 14:23:43 -0700559 return 0;
560}
561
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800562static struct device_node *stdout_path;
563
564static void sysc_init_stdout_path(struct sysc *ddata)
565{
566 struct device_node *np = NULL;
567 const char *uart;
568
569 if (IS_ERR(stdout_path))
570 return;
571
572 if (stdout_path)
573 return;
574
575 np = of_find_node_by_path("/chosen");
576 if (!np)
577 goto err;
578
579 uart = of_get_property(np, "stdout-path", NULL);
580 if (!uart)
581 goto err;
582
583 np = of_find_node_by_path(uart);
584 if (!np)
585 goto err;
586
587 stdout_path = np;
588
589 return;
590
591err:
592 stdout_path = ERR_PTR(-ENODEV);
593}
594
595static void sysc_check_quirk_stdout(struct sysc *ddata,
596 struct device_node *np)
597{
598 sysc_init_stdout_path(ddata);
599 if (np != stdout_path)
600 return;
601
602 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
603 SYSC_QUIRK_NO_RESET_ON_INIT;
604}
605
Tony Lindgren0eecc632017-10-10 14:23:43 -0700606/**
607 * sysc_check_one_child - check child configuration
608 * @ddata: device driver data
609 * @np: child device node
610 *
611 * Let's avoid messy situations where we have new interconnect target
612 * node but children have "ti,hwmods". These belong to the interconnect
613 * target node and are managed by this driver.
614 */
615static int sysc_check_one_child(struct sysc *ddata,
616 struct device_node *np)
617{
618 const char *name;
619
620 name = of_get_property(np, "ti,hwmods", NULL);
621 if (name)
622 dev_warn(ddata->dev, "really a child ti,hwmods property?");
623
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800624 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800625 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800626
Tony Lindgren0eecc632017-10-10 14:23:43 -0700627 return 0;
628}
629
630static int sysc_check_children(struct sysc *ddata)
631{
632 struct device_node *child;
633 int error;
634
635 for_each_child_of_node(ddata->dev->of_node, child) {
636 error = sysc_check_one_child(ddata, child);
637 if (error)
638 return error;
639 }
640
641 return 0;
642}
643
Tony Lindgrena7199e22017-12-15 09:41:14 -0800644/*
645 * So far only I2C uses 16-bit read access with clockactivity with revision
646 * in two registers with stride of 4. We can detect this based on the rev
647 * register size to configure things far enough to be able to properly read
648 * the revision register.
649 */
650static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
651{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800652 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800653 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800654}
655
Tony Lindgren0eecc632017-10-10 14:23:43 -0700656/**
657 * sysc_parse_one - parses the interconnect target module registers
658 * @ddata: device driver data
659 * @reg: register to parse
660 */
661static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
662{
663 struct resource *res;
664 const char *name;
665
666 switch (reg) {
667 case SYSC_REVISION:
668 case SYSC_SYSCONFIG:
669 case SYSC_SYSSTATUS:
670 name = reg_names[reg];
671 break;
672 default:
673 return -EINVAL;
674 }
675
676 res = platform_get_resource_byname(to_platform_device(ddata->dev),
677 IORESOURCE_MEM, name);
678 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700679 ddata->offsets[reg] = -ENODEV;
680
681 return 0;
682 }
683
684 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800685 if (reg == SYSC_REVISION)
686 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700687
688 return 0;
689}
690
691static int sysc_parse_registers(struct sysc *ddata)
692{
693 int i, error;
694
695 for (i = 0; i < SYSC_MAX_REGS; i++) {
696 error = sysc_parse_one(ddata, i);
697 if (error)
698 return error;
699 }
700
701 return 0;
702}
703
704/**
705 * sysc_check_registers - check for misconfigured register overlaps
706 * @ddata: device driver data
707 */
708static int sysc_check_registers(struct sysc *ddata)
709{
710 int i, j, nr_regs = 0, nr_matches = 0;
711
712 for (i = 0; i < SYSC_MAX_REGS; i++) {
713 if (ddata->offsets[i] < 0)
714 continue;
715
716 if (ddata->offsets[i] > (ddata->module_size - 4)) {
717 dev_err(ddata->dev, "register outside module range");
718
719 return -EINVAL;
720 }
721
722 for (j = 0; j < SYSC_MAX_REGS; j++) {
723 if (ddata->offsets[j] < 0)
724 continue;
725
726 if (ddata->offsets[i] == ddata->offsets[j])
727 nr_matches++;
728 }
729 nr_regs++;
730 }
731
Tony Lindgren0eecc632017-10-10 14:23:43 -0700732 if (nr_matches > nr_regs) {
733 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
734 nr_regs, nr_matches);
735
736 return -EINVAL;
737 }
738
739 return 0;
740}
741
742/**
743 * syc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700744 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700745 *
746 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700747 * within the interconnect target module range. For example, SGX has
748 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
749 * has them at offset 0x1200 in the CPSW_WR child. Usually the
750 * the interconnect target module registers are at the beginning of
751 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700752 */
753static int sysc_ioremap(struct sysc *ddata)
754{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700755 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700756
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700757 if (ddata->offsets[SYSC_REVISION] < 0 &&
758 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
759 ddata->offsets[SYSC_SYSSTATUS] < 0) {
760 size = ddata->module_size;
761 } else {
762 size = max3(ddata->offsets[SYSC_REVISION],
763 ddata->offsets[SYSC_SYSCONFIG],
764 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700765
Tony Lindgren4e23be42019-06-10 04:48:05 -0700766 if (size < SZ_1K)
767 size = SZ_1K;
768
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700769 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700770 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700771 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700772
Tony Lindgren0eecc632017-10-10 14:23:43 -0700773 ddata->module_va = devm_ioremap(ddata->dev,
774 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700775 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700776 if (!ddata->module_va)
777 return -EIO;
778
779 return 0;
780}
781
782/**
783 * sysc_map_and_check_registers - ioremap and check device registers
784 * @ddata: device driver data
785 */
786static int sysc_map_and_check_registers(struct sysc *ddata)
787{
788 int error;
789
790 error = sysc_parse_and_check_child_range(ddata);
791 if (error)
792 return error;
793
794 error = sysc_check_children(ddata);
795 if (error)
796 return error;
797
798 error = sysc_parse_registers(ddata);
799 if (error)
800 return error;
801
802 error = sysc_ioremap(ddata);
803 if (error)
804 return error;
805
806 error = sysc_check_registers(ddata);
807 if (error)
808 return error;
809
810 return 0;
811}
812
813/**
814 * sysc_show_rev - read and show interconnect target module revision
815 * @bufp: buffer to print the information to
816 * @ddata: device driver data
817 */
818static int sysc_show_rev(char *bufp, struct sysc *ddata)
819{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800820 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700821
822 if (ddata->offsets[SYSC_REVISION] < 0)
823 return sprintf(bufp, ":NA");
824
Tony Lindgren566a9b052017-12-15 09:41:19 -0800825 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700826
827 return len;
828}
829
830static int sysc_show_reg(struct sysc *ddata,
831 char *bufp, enum sysc_registers reg)
832{
833 if (ddata->offsets[reg] < 0)
834 return sprintf(bufp, ":NA");
835
836 return sprintf(bufp, ":%x", ddata->offsets[reg]);
837}
838
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800839static int sysc_show_name(char *bufp, struct sysc *ddata)
840{
841 if (!ddata->name)
842 return 0;
843
844 return sprintf(bufp, ":%s", ddata->name);
845}
846
Tony Lindgren0eecc632017-10-10 14:23:43 -0700847/**
848 * sysc_show_registers - show information about interconnect target module
849 * @ddata: device driver data
850 */
851static void sysc_show_registers(struct sysc *ddata)
852{
853 char buf[128];
854 char *bufp = buf;
855 int i;
856
857 for (i = 0; i < SYSC_MAX_REGS; i++)
858 bufp += sysc_show_reg(ddata, bufp, i);
859
860 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800861 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700862
863 dev_dbg(ddata->dev, "%llx:%x%s\n",
864 ddata->module_pa, ddata->module_size,
865 buf);
866}
867
Roger Quadrosd59b6052019-04-08 12:52:39 +0300868#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700869#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +0300870
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700871/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300872static int sysc_enable_module(struct device *dev)
873{
874 struct sysc *ddata;
875 const struct sysc_regbits *regbits;
876 u32 reg, idlemodes, best_mode;
877
878 ddata = dev_get_drvdata(dev);
879 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
880 return 0;
881
Roger Quadrosd59b6052019-04-08 12:52:39 +0300882 regbits = ddata->cap->regbits;
883 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
884
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700885 /* Set CLOCKACTIVITY, we only use it for ick */
886 if (regbits->clkact_shift >= 0 &&
887 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT ||
888 ddata->cfg.sysc_val & BIT(regbits->clkact_shift)))
889 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
890
Roger Quadrosd59b6052019-04-08 12:52:39 +0300891 /* Set SIDLE mode */
892 idlemodes = ddata->cfg.sidlemodes;
893 if (!idlemodes || regbits->sidle_shift < 0)
894 goto set_midle;
895
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700896 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
897 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
898 best_mode = SYSC_IDLE_NO;
899 } else {
900 best_mode = fls(ddata->cfg.sidlemodes) - 1;
901 if (best_mode > SYSC_IDLE_MASK) {
902 dev_err(dev, "%s: invalid sidlemode\n", __func__);
903 return -EINVAL;
904 }
Tony Lindgren6e09f492019-05-27 04:51:55 -0700905
906 /* Set WAKEUP */
907 if (regbits->enwkup_shift >= 0 &&
908 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
909 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +0300910 }
911
912 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
913 reg |= best_mode << regbits->sidle_shift;
914 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
915
916set_midle:
917 /* Set MIDLE mode */
918 idlemodes = ddata->cfg.midlemodes;
919 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -0700920 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +0300921
922 best_mode = fls(ddata->cfg.midlemodes) - 1;
923 if (best_mode > SYSC_IDLE_MASK) {
924 dev_err(dev, "%s: invalid midlemode\n", __func__);
925 return -EINVAL;
926 }
927
928 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
929 reg |= best_mode << regbits->midle_shift;
930 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
931
Tony Lindgreneec26552019-05-27 04:51:54 -0700932set_autoidle:
933 /* Autoidle bit must enabled separately if available */
934 if (regbits->autoidle_shift >= 0 &&
935 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
936 reg |= 1 << regbits->autoidle_shift;
937 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
938 }
939
Roger Quadrosd59b6052019-04-08 12:52:39 +0300940 return 0;
941}
942
943static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
944{
945 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
946 *best_mode = SYSC_IDLE_SMART_WKUP;
947 else if (idlemodes & BIT(SYSC_IDLE_SMART))
948 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -0700949 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +0300950 *best_mode = SYSC_IDLE_FORCE;
951 else
952 return -EINVAL;
953
954 return 0;
955}
956
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700957/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300958static int sysc_disable_module(struct device *dev)
959{
960 struct sysc *ddata;
961 const struct sysc_regbits *regbits;
962 u32 reg, idlemodes, best_mode;
963 int ret;
964
965 ddata = dev_get_drvdata(dev);
966 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
967 return 0;
968
Roger Quadrosd59b6052019-04-08 12:52:39 +0300969 regbits = ddata->cap->regbits;
970 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
971
972 /* Set MIDLE mode */
973 idlemodes = ddata->cfg.midlemodes;
974 if (!idlemodes || regbits->midle_shift < 0)
975 goto set_sidle;
976
977 ret = sysc_best_idle_mode(idlemodes, &best_mode);
978 if (ret) {
979 dev_err(dev, "%s: invalid midlemode\n", __func__);
980 return ret;
981 }
982
983 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
984 reg |= best_mode << regbits->midle_shift;
985 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
986
987set_sidle:
988 /* Set SIDLE mode */
989 idlemodes = ddata->cfg.sidlemodes;
990 if (!idlemodes || regbits->sidle_shift < 0)
991 return 0;
992
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700993 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
994 best_mode = SYSC_IDLE_FORCE;
995 } else {
996 ret = sysc_best_idle_mode(idlemodes, &best_mode);
997 if (ret) {
998 dev_err(dev, "%s: invalid sidlemode\n", __func__);
999 return ret;
1000 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001001 }
1002
1003 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1004 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -07001005 if (regbits->autoidle_shift >= 0 &&
1006 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1007 reg |= 1 << regbits->autoidle_shift;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001008 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
1009
1010 return 0;
1011}
1012
Tony Lindgrenff437282019-03-21 11:00:21 -07001013static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1014 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001015{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001016 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001017 int error;
1018
1019 pdata = dev_get_platdata(ddata->dev);
1020 if (!pdata)
1021 return 0;
1022
1023 if (!pdata->idle_module)
1024 return -ENODEV;
1025
1026 error = pdata->idle_module(dev, &ddata->cookie);
1027 if (error)
1028 dev_err(dev, "%s: could not idle: %i\n",
1029 __func__, error);
1030
Tony Lindgren8383e252019-05-27 04:51:56 -07001031 if (ddata->disable_on_idle)
1032 reset_control_assert(ddata->rsts);
1033
Tony Lindgrenff437282019-03-21 11:00:21 -07001034 return 0;
1035}
1036
1037static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1038 struct sysc *ddata)
1039{
1040 struct ti_sysc_platform_data *pdata;
1041 int error;
1042
Tony Lindgren8383e252019-05-27 04:51:56 -07001043 if (ddata->disable_on_idle)
1044 reset_control_deassert(ddata->rsts);
1045
Tony Lindgrenff437282019-03-21 11:00:21 -07001046 pdata = dev_get_platdata(ddata->dev);
1047 if (!pdata)
1048 return 0;
1049
1050 if (!pdata->enable_module)
1051 return -ENODEV;
1052
1053 error = pdata->enable_module(dev, &ddata->cookie);
1054 if (error)
1055 dev_err(dev, "%s: could not enable: %i\n",
1056 __func__, error);
1057
1058 return 0;
1059}
1060
1061static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1062{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001063 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001064 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001065
1066 ddata = dev_get_drvdata(dev);
1067
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001068 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001069 return 0;
1070
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001071 sysc_clkdm_deny_idle(ddata);
1072
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001073 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001074 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001075 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001076 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001077 } else {
1078 error = sysc_disable_module(dev);
1079 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001080 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001081 }
1082
Tony Lindgrend8789702019-03-21 11:00:21 -07001083 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001084
Tony Lindgrend8789702019-03-21 11:00:21 -07001085 if (sysc_opt_clks_needed(ddata))
1086 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001087
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001088 ddata->enabled = false;
1089
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001090err_allow_idle:
1091 sysc_clkdm_allow_idle(ddata);
1092
Tony Lindgren8383e252019-05-27 04:51:56 -07001093 if (ddata->disable_on_idle)
1094 reset_control_assert(ddata->rsts);
1095
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001096 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001097}
1098
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001099static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001100{
1101 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001102 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001103
1104 ddata = dev_get_drvdata(dev);
1105
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001106 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001107 return 0;
1108
Tony Lindgren8383e252019-05-27 04:51:56 -07001109 if (ddata->disable_on_idle)
1110 reset_control_deassert(ddata->rsts);
1111
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001112 sysc_clkdm_deny_idle(ddata);
1113
Tony Lindgrend8789702019-03-21 11:00:21 -07001114 if (sysc_opt_clks_needed(ddata)) {
1115 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001116 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001117 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001118 }
1119
Tony Lindgrend8789702019-03-21 11:00:21 -07001120 error = sysc_enable_main_clocks(ddata);
1121 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001122 goto err_opt_clocks;
1123
1124 if (ddata->legacy_mode) {
1125 error = sysc_runtime_resume_legacy(dev, ddata);
1126 if (error)
1127 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001128 } else {
1129 error = sysc_enable_module(dev);
1130 if (error)
1131 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001132 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001133
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001134 ddata->enabled = true;
1135
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001136 sysc_clkdm_allow_idle(ddata);
1137
Tony Lindgrend8789702019-03-21 11:00:21 -07001138 return 0;
1139
1140err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001141 sysc_disable_main_clocks(ddata);
1142err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001143 if (sysc_opt_clks_needed(ddata))
1144 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001145err_allow_idle:
1146 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001147
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001148 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001149}
1150
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001151static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001152{
1153 struct sysc *ddata;
1154
1155 ddata = dev_get_drvdata(dev);
1156
Tony Lindgren40d9f912018-09-24 12:16:54 -07001157 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001158 return 0;
1159
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001160 return pm_runtime_force_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001161}
1162
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001163static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001164{
1165 struct sysc *ddata;
1166
1167 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001168
Tony Lindgren40d9f912018-09-24 12:16:54 -07001169 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001170 return 0;
1171
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001172 return pm_runtime_force_resume(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001173}
1174
Tony Lindgren0eecc632017-10-10 14:23:43 -07001175static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001176 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001177 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1178 sysc_runtime_resume,
1179 NULL)
1180};
1181
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001182/* Module revision register based quirks */
1183struct sysc_revision_quirk {
1184 const char *name;
1185 u32 base;
1186 int rev_offset;
1187 int sysc_offset;
1188 int syss_offset;
1189 u32 revision;
1190 u32 revision_mask;
1191 u32 quirks;
1192};
1193
1194#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1195 optrev_val, optrevmask, optquirkmask) \
1196 { \
1197 .name = (optname), \
1198 .base = (optbase), \
1199 .rev_offset = (optrev), \
1200 .sysc_offset = (optsysc), \
1201 .syss_offset = (optsyss), \
1202 .revision = (optrev_val), \
1203 .revision_mask = (optrevmask), \
1204 .quirks = (optquirkmask), \
1205 }
1206
1207static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1208 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001209 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -07001210 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001211 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
1212 SYSC_QUIRK_LEGACY_IDLE),
1213 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff,
1214 SYSC_QUIRK_LEGACY_IDLE),
1215 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1216 SYSC_QUIRK_LEGACY_IDLE),
1217 SYSC_QUIRK("smartreflex", 0, -1, 0x24, -1, 0x00000000, 0xffffffff,
1218 SYSC_QUIRK_LEGACY_IDLE),
1219 SYSC_QUIRK("smartreflex", 0, -1, 0x38, -1, 0x00000000, 0xffffffff,
1220 SYSC_QUIRK_LEGACY_IDLE),
1221 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001222 0),
Tony Lindgren8cde5d52018-04-16 10:25:15 -07001223 /* Some timers on omap4 and later */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001224 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x50002100, 0xffffffff,
Tony Lindgren072167d2019-01-29 07:53:47 -08001225 0),
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001226 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x4fff1301, 0xffff00ff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001227 0),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001228 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1229 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001230 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001231 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001232 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001233 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001234 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001235 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001236 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001237
Tony Lindgrena54275f2019-03-21 11:00:21 -07001238 /* Quirks that need to be set based on the module address */
1239 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -1, 0x50000800, 0xffffffff,
1240 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1241 SYSC_QUIRK_SWSUP_SIDLE),
1242
Tony Lindgren4e23be42019-06-10 04:48:05 -07001243 /* Quirks that need to be set based on detected module */
1244 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
1245 SYSC_MODULE_QUIRK_HDQ1W),
1246 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
1247 SYSC_MODULE_QUIRK_HDQ1W),
1248 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
1249 SYSC_MODULE_QUIRK_I2C),
1250 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
1251 SYSC_MODULE_QUIRK_I2C),
1252 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
1253 SYSC_MODULE_QUIRK_I2C),
1254 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
1255 SYSC_MODULE_QUIRK_I2C),
1256 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1257 SYSC_MODULE_QUIRK_WDT),
1258
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001259#ifdef DEBUG
Tony Lindgren1ba30692018-09-24 12:17:05 -07001260 SYSC_QUIRK("adc", 0, 0, 0x10, -1, 0x47300001, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001261 SYSC_QUIRK("atl", 0, 0, -1, -1, 0x0a070100, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001262 SYSC_QUIRK("aess", 0, 0, 0x10, -1, 0x40000000, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001263 SYSC_QUIRK("cm", 0, 0, -1, -1, 0x40000301, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001264 SYSC_QUIRK("control", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001265 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001266 0xffff00f0, 0),
Tony Lindgren89bbc6f2019-07-22 03:44:42 -07001267 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0xa3170504, 0xffffffff, 0),
1268 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren13aad512019-03-21 11:00:21 -07001269 SYSC_QUIRK("dmic", 0, 0, 0x10, -1, 0x50010000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001270 SYSC_QUIRK("dwc3", 0, 0, 0x10, -1, 0x500a0200, 0xffffffff, 0),
1271 SYSC_QUIRK("epwmss", 0, 0, 0x4, -1, 0x47400001, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001272 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -1, 0, 0, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001273 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
1274 SYSC_QUIRK("iss", 0, 0, 0x10, -1, 0x40000101, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001275 SYSC_QUIRK("lcdc", 0, 0, 0x54, -1, 0x4f201000, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001276 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44306302, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001277 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44307b02, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001278 SYSC_QUIRK("mcbsp", 0, -1, 0x8c, -1, 0, 0, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001279 SYSC_QUIRK("mcspi", 0, 0, 0x10, -1, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001280 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001281 SYSC_QUIRK("mailbox", 0, 0, 0x10, -1, 0x00000400, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001282 SYSC_QUIRK("m3", 0, 0, -1, -1, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001283 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001284 SYSC_QUIRK("ocp2scp", 0, 0, -1, -1, 0x50060007, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001285 SYSC_QUIRK("padconf", 0, 0, 0x10, -1, 0x4fff0800, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001286 SYSC_QUIRK("padconf", 0, 0, -1, -1, 0x40001100, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001287 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000100, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001288 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x00004102, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001289 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000400, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001290 SYSC_QUIRK("scm", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001291 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4e8b0100, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001292 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4f000100, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001293 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001294 SYSC_QUIRK("scrm", 0, 0, -1, -1, 0x00000010, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001295 SYSC_QUIRK("sdio", 0, 0, 0x10, -1, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001296 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001297 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001298 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40000902, 0xffffffff, 0),
1299 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40002903, 0xffffffff, 0),
1300 SYSC_QUIRK("spinlock", 0, 0, 0x10, -1, 0x50020000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001301 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -1, 0x00000020, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001302 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -1, 0x4eb01908, 0xffff00f0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001303 SYSC_QUIRK("timer32k", 0, 0, 0x4, -1, 0x00000060, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001304 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001305 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001306 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001307 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -1, 0x50700101, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001308 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1309 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001310 SYSC_QUIRK("vfpe", 0, 0, 0x104, -1, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001311#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001312};
1313
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001314/*
1315 * Early quirks based on module base and register offsets only that are
1316 * needed before the module revision can be read
1317 */
1318static void sysc_init_early_quirks(struct sysc *ddata)
1319{
1320 const struct sysc_revision_quirk *q;
1321 int i;
1322
1323 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1324 q = &sysc_revision_quirks[i];
1325
1326 if (!q->base)
1327 continue;
1328
1329 if (q->base != ddata->module_pa)
1330 continue;
1331
1332 if (q->rev_offset >= 0 &&
1333 q->rev_offset != ddata->offsets[SYSC_REVISION])
1334 continue;
1335
1336 if (q->sysc_offset >= 0 &&
1337 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1338 continue;
1339
1340 if (q->syss_offset >= 0 &&
1341 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1342 continue;
1343
1344 ddata->name = q->name;
1345 ddata->cfg.quirks |= q->quirks;
1346 }
1347}
1348
1349/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001350static void sysc_init_revision_quirks(struct sysc *ddata)
1351{
1352 const struct sysc_revision_quirk *q;
1353 int i;
1354
1355 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1356 q = &sysc_revision_quirks[i];
1357
1358 if (q->base && q->base != ddata->module_pa)
1359 continue;
1360
1361 if (q->rev_offset >= 0 &&
1362 q->rev_offset != ddata->offsets[SYSC_REVISION])
1363 continue;
1364
1365 if (q->sysc_offset >= 0 &&
1366 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1367 continue;
1368
1369 if (q->syss_offset >= 0 &&
1370 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1371 continue;
1372
1373 if (q->revision == ddata->revision ||
1374 (q->revision & q->revision_mask) ==
1375 (ddata->revision & q->revision_mask)) {
1376 ddata->name = q->name;
1377 ddata->cfg.quirks |= q->quirks;
1378 }
1379 }
1380}
1381
Tony Lindgren4e23be42019-06-10 04:48:05 -07001382/* 1-wire needs module's internal clocks enabled for reset */
1383static void sysc_clk_enable_quirk_hdq1w(struct sysc *ddata)
1384{
1385 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1386 u16 val;
1387
1388 val = sysc_read(ddata, offset);
1389 val |= BIT(5);
1390 sysc_write(ddata, offset, val);
1391}
1392
1393/* I2C needs extra enable bit toggling for reset */
1394static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1395{
1396 int offset;
1397 u16 val;
1398
1399 /* I2C_CON, omap2/3 is different from omap4 and later */
1400 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1401 offset = 0x24;
1402 else
1403 offset = 0xa4;
1404
1405 /* I2C_EN */
1406 val = sysc_read(ddata, offset);
1407 if (enable)
1408 val |= BIT(15);
1409 else
1410 val &= ~BIT(15);
1411 sysc_write(ddata, offset, val);
1412}
1413
1414static void sysc_clk_enable_quirk_i2c(struct sysc *ddata)
1415{
1416 sysc_clk_quirk_i2c(ddata, true);
1417}
1418
1419static void sysc_clk_disable_quirk_i2c(struct sysc *ddata)
1420{
1421 sysc_clk_quirk_i2c(ddata, false);
1422}
1423
1424/* Watchdog timer needs a disable sequence after reset */
1425static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1426{
1427 int wps, spr, error;
1428 u32 val;
1429
1430 wps = 0x34;
1431 spr = 0x48;
1432
1433 sysc_write(ddata, spr, 0xaaaa);
1434 error = readl_poll_timeout(ddata->module_va + wps, val,
1435 !(val & 0x10), 100,
1436 MAX_MODULE_SOFTRESET_WAIT);
1437 if (error)
1438 dev_warn(ddata->dev, "wdt disable spr failed\n");
1439
1440 sysc_write(ddata, wps, 0x5555);
1441 error = readl_poll_timeout(ddata->module_va + wps, val,
1442 !(val & 0x10), 100,
1443 MAX_MODULE_SOFTRESET_WAIT);
1444 if (error)
1445 dev_warn(ddata->dev, "wdt disable wps failed\n");
1446}
1447
1448static void sysc_init_module_quirks(struct sysc *ddata)
1449{
1450 if (ddata->legacy_mode || !ddata->name)
1451 return;
1452
1453 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
1454 ddata->clk_enable_quirk = sysc_clk_enable_quirk_hdq1w;
1455
1456 return;
1457 }
1458
1459 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
1460 ddata->clk_enable_quirk = sysc_clk_enable_quirk_i2c;
1461 ddata->clk_disable_quirk = sysc_clk_disable_quirk_i2c;
1462
1463 return;
1464 }
1465
1466 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT)
1467 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
1468}
1469
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001470static int sysc_clockdomain_init(struct sysc *ddata)
1471{
1472 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1473 struct clk *fck = NULL, *ick = NULL;
1474 int error;
1475
1476 if (!pdata || !pdata->init_clockdomain)
1477 return 0;
1478
1479 switch (ddata->nr_clocks) {
1480 case 2:
1481 ick = ddata->clocks[SYSC_ICK];
1482 /* fallthrough */
1483 case 1:
1484 fck = ddata->clocks[SYSC_FCK];
1485 break;
1486 case 0:
1487 return 0;
1488 }
1489
1490 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
1491 if (!error || error == -ENODEV)
1492 return 0;
1493
1494 return error;
1495}
1496
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001497/*
1498 * Note that pdata->init_module() typically does a reset first. After
1499 * pdata->init_module() is done, PM runtime can be used for the interconnect
1500 * target module.
1501 */
1502static int sysc_legacy_init(struct sysc *ddata)
1503{
1504 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1505 int error;
1506
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001507 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001508 return 0;
1509
1510 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
1511 if (error == -EEXIST)
1512 error = 0;
1513
1514 return error;
1515}
1516
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001517/**
1518 * sysc_rstctrl_reset_deassert - deassert rstctrl reset
1519 * @ddata: device driver data
1520 * @reset: reset before deassert
1521 *
1522 * A module can have both OCP softreset control and external rstctrl.
1523 * If more complicated rstctrl resets are needed, please handle these
1524 * directly from the child device driver and map only the module reset
1525 * for the parent interconnect target module device.
1526 *
1527 * Automatic reset of the module on init can be skipped with the
1528 * "ti,no-reset-on-init" device tree property.
1529 */
1530static int sysc_rstctrl_reset_deassert(struct sysc *ddata, bool reset)
1531{
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001532 int error, val;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001533
1534 if (!ddata->rsts)
1535 return 0;
1536
1537 if (reset) {
1538 error = reset_control_assert(ddata->rsts);
1539 if (error)
1540 return error;
1541 }
1542
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001543 error = reset_control_deassert(ddata->rsts);
1544 if (error == -EEXIST)
1545 return 0;
1546
1547 error = readx_poll_timeout(reset_control_status, ddata->rsts, val,
1548 val == 0, 100, MAX_MODULE_SOFTRESET_WAIT);
1549
1550 return error;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001551}
1552
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001553/*
1554 * Note that the caller must ensure the interconnect target module is enabled
1555 * before calling reset. Otherwise reset will not complete.
1556 */
Faiz Abbas596e7952018-07-09 22:18:39 +05301557static int sysc_reset(struct sysc *ddata)
1558{
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001559 int sysc_offset, syss_offset, sysc_val, rstval, quirks, error = 0;
1560 u32 sysc_mask, syss_done;
Faiz Abbas596e7952018-07-09 22:18:39 +05301561
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001562 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
1563 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
1564 quirks = ddata->cfg.quirks;
1565
1566 if (ddata->legacy_mode || sysc_offset < 0 ||
1567 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05301568 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
1569 return 0;
1570
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001571 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05301572
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001573 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
1574 syss_done = 0;
1575 else
1576 syss_done = ddata->cfg.syss_mask;
1577
Tony Lindgren4e23be42019-06-10 04:48:05 -07001578 if (ddata->clk_disable_quirk)
1579 ddata->clk_disable_quirk(ddata);
1580
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001581 sysc_val = sysc_read_sysconfig(ddata);
1582 sysc_val |= sysc_mask;
1583 sysc_write(ddata, sysc_offset, sysc_val);
Faiz Abbas596e7952018-07-09 22:18:39 +05301584
Tony Lindgren4e23be42019-06-10 04:48:05 -07001585 if (ddata->clk_enable_quirk)
1586 ddata->clk_enable_quirk(ddata);
1587
Faiz Abbas596e7952018-07-09 22:18:39 +05301588 /* Poll on reset status */
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001589 if (syss_offset >= 0) {
1590 error = readx_poll_timeout(sysc_read_sysstatus, ddata, rstval,
1591 (rstval & ddata->cfg.syss_mask) ==
1592 syss_done,
1593 100, MAX_MODULE_SOFTRESET_WAIT);
Faiz Abbas596e7952018-07-09 22:18:39 +05301594
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001595 } else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS) {
1596 error = readx_poll_timeout(sysc_read_sysconfig, ddata, rstval,
1597 !(rstval & sysc_mask),
1598 100, MAX_MODULE_SOFTRESET_WAIT);
1599 }
1600
Tony Lindgren4e23be42019-06-10 04:48:05 -07001601 if (ddata->reset_done_quirk)
1602 ddata->reset_done_quirk(ddata);
1603
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001604 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05301605}
1606
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001607/*
1608 * At this point the module is configured enough to read the revision but
1609 * module may not be completely configured yet to use PM runtime. Enable
1610 * all clocks directly during init to configure the quirks needed for PM
1611 * runtime based on the revision register.
1612 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08001613static int sysc_init_module(struct sysc *ddata)
1614{
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001615 int error = 0;
1616 bool manage_clocks = true;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001617
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001618 error = sysc_rstctrl_reset_deassert(ddata, false);
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001619 if (error)
1620 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001621
Tony Lindgren386cb762019-03-22 07:49:30 -07001622 if (ddata->cfg.quirks &
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001623 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))
1624 manage_clocks = false;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001625
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001626 error = sysc_clockdomain_init(ddata);
1627 if (error)
1628 return error;
1629
Tony Lindgrend0989132019-09-05 07:37:22 -07001630 sysc_clkdm_deny_idle(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001631
Tony Lindgrend0989132019-09-05 07:37:22 -07001632 /*
1633 * Always enable clocks. The bootloader may or may not have enabled
1634 * the related clocks.
1635 */
1636 error = sysc_enable_opt_clocks(ddata);
1637 if (error)
1638 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001639
Tony Lindgrend0989132019-09-05 07:37:22 -07001640 error = sysc_enable_main_clocks(ddata);
1641 if (error)
1642 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05301643
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001644 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
1645 error = sysc_rstctrl_reset_deassert(ddata, true);
1646 if (error)
1647 goto err_main_clocks;
1648 }
1649
Tony Lindgren566a9b052017-12-15 09:41:19 -08001650 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001651 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001652 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001653
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001654 if (ddata->legacy_mode) {
1655 error = sysc_legacy_init(ddata);
1656 if (error)
1657 goto err_main_clocks;
1658 }
1659
Tony Lindgrend0989132019-09-05 07:37:22 -07001660 if (!ddata->legacy_mode) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001661 error = sysc_enable_module(ddata->dev);
1662 if (error)
1663 goto err_main_clocks;
1664 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001665
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001666 error = sysc_reset(ddata);
1667 if (error)
1668 dev_err(ddata->dev, "Reset failed with %d\n", error);
1669
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001670 if (!ddata->legacy_mode && manage_clocks)
1671 sysc_disable_module(ddata->dev);
1672
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001673err_main_clocks:
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001674 if (manage_clocks)
1675 sysc_disable_main_clocks(ddata);
1676err_opt_clocks:
Tony Lindgrend0989132019-09-05 07:37:22 -07001677 /* No re-enable of clockdomain autoidle to prevent module autoidle */
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001678 if (manage_clocks) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001679 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001680 sysc_clkdm_allow_idle(ddata);
1681 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001682
1683 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001684}
1685
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001686static int sysc_init_sysc_mask(struct sysc *ddata)
1687{
1688 struct device_node *np = ddata->dev->of_node;
1689 int error;
1690 u32 val;
1691
1692 error = of_property_read_u32(np, "ti,sysc-mask", &val);
1693 if (error)
1694 return 0;
1695
Tony Lindgrene212abd2019-07-22 03:44:52 -07001696 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001697
1698 return 0;
1699}
1700
1701static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
1702 const char *name)
1703{
1704 struct device_node *np = ddata->dev->of_node;
1705 struct property *prop;
1706 const __be32 *p;
1707 u32 val;
1708
1709 of_property_for_each_u32(np, name, prop, p, val) {
1710 if (val >= SYSC_NR_IDLEMODES) {
1711 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
1712 return -EINVAL;
1713 }
1714 *idlemodes |= (1 << val);
1715 }
1716
1717 return 0;
1718}
1719
1720static int sysc_init_idlemodes(struct sysc *ddata)
1721{
1722 int error;
1723
1724 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
1725 "ti,sysc-midle");
1726 if (error)
1727 return error;
1728
1729 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
1730 "ti,sysc-sidle");
1731 if (error)
1732 return error;
1733
1734 return 0;
1735}
1736
1737/*
1738 * Only some devices on omap4 and later have SYSCONFIG reset done
1739 * bit. We can detect this if there is no SYSSTATUS at all, or the
1740 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
1741 * have multiple bits for the child devices like OHCI and EHCI.
1742 * Depends on SYSC being parsed first.
1743 */
1744static int sysc_init_syss_mask(struct sysc *ddata)
1745{
1746 struct device_node *np = ddata->dev->of_node;
1747 int error;
1748 u32 val;
1749
1750 error = of_property_read_u32(np, "ti,syss-mask", &val);
1751 if (error) {
1752 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
1753 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
1754 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1755 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1756
1757 return 0;
1758 }
1759
1760 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1761 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1762
1763 ddata->cfg.syss_mask = val;
1764
1765 return 0;
1766}
1767
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001768/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001769 * Many child device drivers need to have fck and opt clocks available
1770 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001771 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001772static int sysc_child_add_named_clock(struct sysc *ddata,
1773 struct device *child,
1774 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001775{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001776 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001777 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001778 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001779
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001780 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001781 return 0;
1782
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001783 clk = clk_get(child, name);
1784 if (!IS_ERR(clk)) {
1785 clk_put(clk);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001786
1787 return -EEXIST;
1788 }
1789
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001790 clk = clk_get(ddata->dev, name);
1791 if (IS_ERR(clk))
1792 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001793
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001794 l = clkdev_create(clk, name, dev_name(child));
1795 if (!l)
1796 error = -ENOMEM;
1797
1798 clk_put(clk);
1799
1800 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001801}
1802
Tony Lindgren09dfe582018-04-16 10:25:52 -07001803static int sysc_child_add_clocks(struct sysc *ddata,
1804 struct device *child)
1805{
1806 int i, error;
1807
1808 for (i = 0; i < ddata->nr_clocks; i++) {
1809 error = sysc_child_add_named_clock(ddata,
1810 child,
1811 ddata->clock_roles[i]);
1812 if (error && error != -EEXIST) {
1813 dev_err(ddata->dev, "could not add child clock %s: %i\n",
1814 ddata->clock_roles[i], error);
1815
1816 return error;
1817 }
1818 }
1819
1820 return 0;
1821}
1822
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001823static struct device_type sysc_device_type = {
1824};
1825
1826static struct sysc *sysc_child_to_parent(struct device *dev)
1827{
1828 struct device *parent = dev->parent;
1829
1830 if (!parent || parent->type != &sysc_device_type)
1831 return NULL;
1832
1833 return dev_get_drvdata(parent);
1834}
1835
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001836static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
1837{
1838 struct sysc *ddata;
1839 int error;
1840
1841 ddata = sysc_child_to_parent(dev);
1842
1843 error = pm_generic_runtime_suspend(dev);
1844 if (error)
1845 return error;
1846
1847 if (!ddata->enabled)
1848 return 0;
1849
1850 return sysc_runtime_suspend(ddata->dev);
1851}
1852
1853static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
1854{
1855 struct sysc *ddata;
1856 int error;
1857
1858 ddata = sysc_child_to_parent(dev);
1859
1860 if (!ddata->enabled) {
1861 error = sysc_runtime_resume(ddata->dev);
1862 if (error < 0)
1863 dev_err(ddata->dev,
1864 "%s error: %i\n", __func__, error);
1865 }
1866
1867 return pm_generic_runtime_resume(dev);
1868}
1869
1870#ifdef CONFIG_PM_SLEEP
1871static int sysc_child_suspend_noirq(struct device *dev)
1872{
1873 struct sysc *ddata;
1874 int error;
1875
1876 ddata = sysc_child_to_parent(dev);
1877
Tony Lindgrenef55f822018-04-16 10:27:15 -07001878 dev_dbg(ddata->dev, "%s %s\n", __func__,
1879 ddata->name ? ddata->name : "");
1880
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001881 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001882 if (error) {
1883 dev_err(dev, "%s error at %i: %i\n",
1884 __func__, __LINE__, error);
1885
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001886 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001887 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001888
1889 if (!pm_runtime_status_suspended(dev)) {
1890 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001891 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07001892 dev_dbg(dev, "%s busy at %i: %i\n",
1893 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001894
Tony Lindgren4f3530f2018-08-08 01:07:06 -07001895 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001896 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001897
1898 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001899 if (error) {
1900 dev_err(dev, "%s error at %i: %i\n",
1901 __func__, __LINE__, error);
1902
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001903 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001904 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001905
1906 ddata->child_needs_resume = true;
1907 }
1908
1909 return 0;
1910}
1911
1912static int sysc_child_resume_noirq(struct device *dev)
1913{
1914 struct sysc *ddata;
1915 int error;
1916
1917 ddata = sysc_child_to_parent(dev);
1918
Tony Lindgrenef55f822018-04-16 10:27:15 -07001919 dev_dbg(ddata->dev, "%s %s\n", __func__,
1920 ddata->name ? ddata->name : "");
1921
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001922 if (ddata->child_needs_resume) {
1923 ddata->child_needs_resume = false;
1924
1925 error = sysc_runtime_resume(ddata->dev);
1926 if (error)
1927 dev_err(ddata->dev,
1928 "%s runtime resume error: %i\n",
1929 __func__, error);
1930
1931 error = pm_generic_runtime_resume(dev);
1932 if (error)
1933 dev_err(ddata->dev,
1934 "%s generic runtime resume: %i\n",
1935 __func__, error);
1936 }
1937
1938 return pm_generic_resume_noirq(dev);
1939}
1940#endif
1941
Tony Lindgrenb7182b42019-03-21 11:00:21 -07001942static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001943 .ops = {
1944 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
1945 sysc_child_runtime_resume,
1946 NULL)
1947 USE_PLATFORM_PM_SLEEP_OPS
1948 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
1949 sysc_child_resume_noirq)
1950 }
1951};
1952
1953/**
1954 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
1955 * @ddata: device driver data
1956 * @child: child device driver
1957 *
1958 * Allow idle for child devices as done with _od_runtime_suspend().
1959 * Otherwise many child devices will not idle because of the permanent
1960 * parent usecount set in pm_runtime_irq_safe().
1961 *
1962 * Note that the long term solution is to just modify the child device
1963 * drivers to not set pm_runtime_irq_safe() and then this can be just
1964 * dropped.
1965 */
1966static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
1967{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001968 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
1969 dev_pm_domain_set(child, &sysc_child_pm_domain);
1970}
1971
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001972static int sysc_notifier_call(struct notifier_block *nb,
1973 unsigned long event, void *device)
1974{
1975 struct device *dev = device;
1976 struct sysc *ddata;
1977 int error;
1978
1979 ddata = sysc_child_to_parent(dev);
1980 if (!ddata)
1981 return NOTIFY_DONE;
1982
1983 switch (event) {
1984 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07001985 error = sysc_child_add_clocks(ddata, dev);
1986 if (error)
1987 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001988 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001989 break;
1990 default:
1991 break;
1992 }
1993
1994 return NOTIFY_DONE;
1995}
1996
1997static struct notifier_block sysc_nb = {
1998 .notifier_call = sysc_notifier_call,
1999};
2000
Tony Lindgren566a9b052017-12-15 09:41:19 -08002001/* Device tree configured quirks */
2002struct sysc_dts_quirk {
2003 const char *name;
2004 u32 mask;
2005};
2006
2007static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2008 { .name = "ti,no-idle-on-init",
2009 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2010 { .name = "ti,no-reset-on-init",
2011 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002012 { .name = "ti,no-idle",
2013 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002014};
2015
Tony Lindgren4014c082018-12-10 14:11:26 -08002016static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2017 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002018{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002019 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002020 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002021
2022 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002023 const char *name = sysc_dts_quirks[i].name;
2024
2025 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002026 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002027 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002028
2029 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002030 if (is_child) {
2031 dev_warn(ddata->dev,
2032 "dts flag should be at module level for %s\n",
2033 name);
2034 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002035 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002036}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002037
Tony Lindgren4014c082018-12-10 14:11:26 -08002038static int sysc_init_dts_quirks(struct sysc *ddata)
2039{
2040 struct device_node *np = ddata->dev->of_node;
2041 int error;
2042 u32 val;
2043
2044 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2045
2046 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002047 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2048 if (!error) {
2049 if (val > 255) {
2050 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2051 val);
2052 }
2053
2054 ddata->cfg.srst_udelay = (u8)val;
2055 }
2056
2057 return 0;
2058}
2059
Tony Lindgren0eecc632017-10-10 14:23:43 -07002060static void sysc_unprepare(struct sysc *ddata)
2061{
2062 int i;
2063
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002064 if (!ddata->clocks)
2065 return;
2066
Tony Lindgren0eecc632017-10-10 14:23:43 -07002067 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2068 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2069 clk_unprepare(ddata->clocks[i]);
2070 }
2071}
2072
Tony Lindgren70a65242017-12-15 09:41:09 -08002073/*
2074 * Common sysc register bits found on omap2, also known as type1
2075 */
2076static const struct sysc_regbits sysc_regbits_omap2 = {
2077 .dmadisable_shift = -ENODEV,
2078 .midle_shift = 12,
2079 .sidle_shift = 3,
2080 .clkact_shift = 8,
2081 .emufree_shift = 5,
2082 .enwkup_shift = 2,
2083 .srst_shift = 1,
2084 .autoidle_shift = 0,
2085};
2086
2087static const struct sysc_capabilities sysc_omap2 = {
2088 .type = TI_SYSC_OMAP2,
2089 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2090 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2091 SYSC_OMAP2_AUTOIDLE,
2092 .regbits = &sysc_regbits_omap2,
2093};
2094
2095/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2096static const struct sysc_capabilities sysc_omap2_timer = {
2097 .type = TI_SYSC_OMAP2_TIMER,
2098 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2099 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2100 SYSC_OMAP2_AUTOIDLE,
2101 .regbits = &sysc_regbits_omap2,
2102 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2103};
2104
2105/*
2106 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2107 * with different sidle position
2108 */
2109static const struct sysc_regbits sysc_regbits_omap3_sham = {
2110 .dmadisable_shift = -ENODEV,
2111 .midle_shift = -ENODEV,
2112 .sidle_shift = 4,
2113 .clkact_shift = -ENODEV,
2114 .enwkup_shift = -ENODEV,
2115 .srst_shift = 1,
2116 .autoidle_shift = 0,
2117 .emufree_shift = -ENODEV,
2118};
2119
2120static const struct sysc_capabilities sysc_omap3_sham = {
2121 .type = TI_SYSC_OMAP3_SHAM,
2122 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2123 .regbits = &sysc_regbits_omap3_sham,
2124};
2125
2126/*
2127 * AES register bits found on omap3 and later, a variant of
2128 * sysc_regbits_omap2 with different sidle position
2129 */
2130static const struct sysc_regbits sysc_regbits_omap3_aes = {
2131 .dmadisable_shift = -ENODEV,
2132 .midle_shift = -ENODEV,
2133 .sidle_shift = 6,
2134 .clkact_shift = -ENODEV,
2135 .enwkup_shift = -ENODEV,
2136 .srst_shift = 1,
2137 .autoidle_shift = 0,
2138 .emufree_shift = -ENODEV,
2139};
2140
2141static const struct sysc_capabilities sysc_omap3_aes = {
2142 .type = TI_SYSC_OMAP3_AES,
2143 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2144 .regbits = &sysc_regbits_omap3_aes,
2145};
2146
2147/*
2148 * Common sysc register bits found on omap4, also known as type2
2149 */
2150static const struct sysc_regbits sysc_regbits_omap4 = {
2151 .dmadisable_shift = 16,
2152 .midle_shift = 4,
2153 .sidle_shift = 2,
2154 .clkact_shift = -ENODEV,
2155 .enwkup_shift = -ENODEV,
2156 .emufree_shift = 1,
2157 .srst_shift = 0,
2158 .autoidle_shift = -ENODEV,
2159};
2160
2161static const struct sysc_capabilities sysc_omap4 = {
2162 .type = TI_SYSC_OMAP4,
2163 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2164 SYSC_OMAP4_SOFTRESET,
2165 .regbits = &sysc_regbits_omap4,
2166};
2167
2168static const struct sysc_capabilities sysc_omap4_timer = {
2169 .type = TI_SYSC_OMAP4_TIMER,
2170 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2171 SYSC_OMAP4_SOFTRESET,
2172 .regbits = &sysc_regbits_omap4,
2173};
2174
2175/*
2176 * Common sysc register bits found on omap4, also known as type3
2177 */
2178static const struct sysc_regbits sysc_regbits_omap4_simple = {
2179 .dmadisable_shift = -ENODEV,
2180 .midle_shift = 2,
2181 .sidle_shift = 0,
2182 .clkact_shift = -ENODEV,
2183 .enwkup_shift = -ENODEV,
2184 .srst_shift = -ENODEV,
2185 .emufree_shift = -ENODEV,
2186 .autoidle_shift = -ENODEV,
2187};
2188
2189static const struct sysc_capabilities sysc_omap4_simple = {
2190 .type = TI_SYSC_OMAP4_SIMPLE,
2191 .regbits = &sysc_regbits_omap4_simple,
2192};
2193
2194/*
2195 * SmartReflex sysc found on omap34xx
2196 */
2197static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2198 .dmadisable_shift = -ENODEV,
2199 .midle_shift = -ENODEV,
2200 .sidle_shift = -ENODEV,
2201 .clkact_shift = 20,
2202 .enwkup_shift = -ENODEV,
2203 .srst_shift = -ENODEV,
2204 .emufree_shift = -ENODEV,
2205 .autoidle_shift = -ENODEV,
2206};
2207
2208static const struct sysc_capabilities sysc_34xx_sr = {
2209 .type = TI_SYSC_OMAP34XX_SR,
2210 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2211 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002212 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2213 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002214};
2215
2216/*
2217 * SmartReflex sysc found on omap36xx and later
2218 */
2219static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2220 .dmadisable_shift = -ENODEV,
2221 .midle_shift = -ENODEV,
2222 .sidle_shift = 24,
2223 .clkact_shift = -ENODEV,
2224 .enwkup_shift = 26,
2225 .srst_shift = -ENODEV,
2226 .emufree_shift = -ENODEV,
2227 .autoidle_shift = -ENODEV,
2228};
2229
2230static const struct sysc_capabilities sysc_36xx_sr = {
2231 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002232 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002233 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002234 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002235};
2236
2237static const struct sysc_capabilities sysc_omap4_sr = {
2238 .type = TI_SYSC_OMAP4_SR,
2239 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002240 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002241};
2242
2243/*
2244 * McASP register bits found on omap4 and later
2245 */
2246static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2247 .dmadisable_shift = -ENODEV,
2248 .midle_shift = -ENODEV,
2249 .sidle_shift = 0,
2250 .clkact_shift = -ENODEV,
2251 .enwkup_shift = -ENODEV,
2252 .srst_shift = -ENODEV,
2253 .emufree_shift = -ENODEV,
2254 .autoidle_shift = -ENODEV,
2255};
2256
2257static const struct sysc_capabilities sysc_omap4_mcasp = {
2258 .type = TI_SYSC_OMAP4_MCASP,
2259 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002260 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2261};
2262
2263/*
2264 * McASP found on dra7 and later
2265 */
2266static const struct sysc_capabilities sysc_dra7_mcasp = {
2267 .type = TI_SYSC_OMAP4_SIMPLE,
2268 .regbits = &sysc_regbits_omap4_simple,
2269 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002270};
2271
2272/*
2273 * FS USB host found on omap4 and later
2274 */
2275static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2276 .dmadisable_shift = -ENODEV,
2277 .midle_shift = -ENODEV,
2278 .sidle_shift = 24,
2279 .clkact_shift = -ENODEV,
2280 .enwkup_shift = 26,
2281 .srst_shift = -ENODEV,
2282 .emufree_shift = -ENODEV,
2283 .autoidle_shift = -ENODEV,
2284};
2285
2286static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2287 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2288 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2289 .regbits = &sysc_regbits_omap4_usb_host_fs,
2290};
2291
Faiz Abbas7f35e632018-07-09 22:18:38 +05302292static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2293 .dmadisable_shift = -ENODEV,
2294 .midle_shift = -ENODEV,
2295 .sidle_shift = -ENODEV,
2296 .clkact_shift = -ENODEV,
2297 .enwkup_shift = 4,
2298 .srst_shift = 0,
2299 .emufree_shift = -ENODEV,
2300 .autoidle_shift = -ENODEV,
2301};
2302
2303static const struct sysc_capabilities sysc_dra7_mcan = {
2304 .type = TI_SYSC_DRA7_MCAN,
2305 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2306 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002307 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302308};
2309
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002310static int sysc_init_pdata(struct sysc *ddata)
2311{
2312 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002313 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002314
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002315 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002316 return 0;
2317
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002318 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2319 if (!mdata)
2320 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002321
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002322 if (ddata->legacy_mode) {
2323 mdata->name = ddata->legacy_mode;
2324 mdata->module_pa = ddata->module_pa;
2325 mdata->module_size = ddata->module_size;
2326 mdata->offsets = ddata->offsets;
2327 mdata->nr_offsets = SYSC_MAX_REGS;
2328 mdata->cap = ddata->cap;
2329 mdata->cfg = &ddata->cfg;
2330 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002331
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002332 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002333
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002334 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002335}
2336
Tony Lindgren70a65242017-12-15 09:41:09 -08002337static int sysc_init_match(struct sysc *ddata)
2338{
2339 const struct sysc_capabilities *cap;
2340
2341 cap = of_device_get_match_data(ddata->dev);
2342 if (!cap)
2343 return -EINVAL;
2344
2345 ddata->cap = cap;
2346 if (ddata->cap)
2347 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2348
2349 return 0;
2350}
2351
Tony Lindgren76f0f772018-02-23 08:28:45 -08002352static void ti_sysc_idle(struct work_struct *work)
2353{
2354 struct sysc *ddata;
2355
2356 ddata = container_of(work, struct sysc, idle_work.work);
2357
Tony Lindgrend0989132019-09-05 07:37:22 -07002358 /*
2359 * One time decrement of clock usage counts if left on from init.
2360 * Note that we disable opt clocks unconditionally in this case
2361 * as they are enabled unconditionally during init without
2362 * considering sysc_opt_clks_needed() at that point.
2363 */
2364 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2365 SYSC_QUIRK_NO_IDLE_ON_INIT)) {
2366 sysc_clkdm_deny_idle(ddata);
2367 sysc_disable_main_clocks(ddata);
2368 sysc_disable_opt_clocks(ddata);
2369 sysc_clkdm_allow_idle(ddata);
2370 }
2371
2372 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
2373 if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE)
2374 return;
2375
2376 /*
2377 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
2378 * and SYSC_QUIRK_NO_RESET_ON_INIT
2379 */
Tony Lindgren76f0f772018-02-23 08:28:45 -08002380 if (pm_runtime_active(ddata->dev))
2381 pm_runtime_put_sync(ddata->dev);
2382}
2383
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002384static const struct of_device_id sysc_match_table[] = {
2385 { .compatible = "simple-bus", },
2386 { /* sentinel */ },
2387};
2388
Tony Lindgren0eecc632017-10-10 14:23:43 -07002389static int sysc_probe(struct platform_device *pdev)
2390{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002391 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002392 struct sysc *ddata;
2393 int error;
2394
2395 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
2396 if (!ddata)
2397 return -ENOMEM;
2398
2399 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002400 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002401
Tony Lindgren70a65242017-12-15 09:41:09 -08002402 error = sysc_init_match(ddata);
2403 if (error)
2404 return error;
2405
Tony Lindgren566a9b052017-12-15 09:41:19 -08002406 error = sysc_init_dts_quirks(ddata);
2407 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002408 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002409
Tony Lindgren0eecc632017-10-10 14:23:43 -07002410 error = sysc_map_and_check_registers(ddata);
2411 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002412 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07002413
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002414 error = sysc_init_sysc_mask(ddata);
2415 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002416 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002417
2418 error = sysc_init_idlemodes(ddata);
2419 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002420 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002421
2422 error = sysc_init_syss_mask(ddata);
2423 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002424 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002425
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002426 error = sysc_init_pdata(ddata);
2427 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002428 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002429
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07002430 sysc_init_early_quirks(ddata);
2431
2432 error = sysc_get_clocks(ddata);
2433 if (error)
2434 return error;
2435
Tony Lindgren50622362018-04-16 10:20:27 -07002436 error = sysc_init_resets(ddata);
2437 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002438 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002439
2440 error = sysc_init_module(ddata);
2441 if (error)
2442 goto unprepare;
2443
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002444 pm_runtime_enable(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002445 error = pm_runtime_get_sync(ddata->dev);
2446 if (error < 0) {
2447 pm_runtime_put_noidle(ddata->dev);
2448 pm_runtime_disable(ddata->dev);
2449 goto unprepare;
2450 }
2451
Tony Lindgren0eecc632017-10-10 14:23:43 -07002452 sysc_show_registers(ddata);
2453
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002454 ddata->dev->type = &sysc_device_type;
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002455 error = of_platform_populate(ddata->dev->of_node, sysc_match_table,
2456 pdata ? pdata->auxdata : NULL,
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002457 ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002458 if (error)
2459 goto err;
2460
Tony Lindgren76f0f772018-02-23 08:28:45 -08002461 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
2462
2463 /* At least earlycon won't survive without deferred idle */
Tony Lindgrend0989132019-09-05 07:37:22 -07002464 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2465 SYSC_QUIRK_NO_IDLE_ON_INIT |
Tony Lindgren76f0f772018-02-23 08:28:45 -08002466 SYSC_QUIRK_NO_RESET_ON_INIT)) {
2467 schedule_delayed_work(&ddata->idle_work, 3000);
2468 } else {
2469 pm_runtime_put(&pdev->dev);
2470 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07002471
Tony Lindgren50622362018-04-16 10:20:27 -07002472 if (!of_get_available_child_count(ddata->dev->of_node))
Tony Lindgren8383e252019-05-27 04:51:56 -07002473 ddata->disable_on_idle = true;
Tony Lindgren50622362018-04-16 10:20:27 -07002474
Tony Lindgren0eecc632017-10-10 14:23:43 -07002475 return 0;
2476
2477err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07002478 pm_runtime_put_sync(&pdev->dev);
2479 pm_runtime_disable(&pdev->dev);
2480unprepare:
2481 sysc_unprepare(ddata);
2482
2483 return error;
2484}
2485
Tony Lindgren684be5a2017-10-13 10:48:40 -07002486static int sysc_remove(struct platform_device *pdev)
2487{
2488 struct sysc *ddata = platform_get_drvdata(pdev);
2489 int error;
2490
Tony Lindgren76f0f772018-02-23 08:28:45 -08002491 cancel_delayed_work_sync(&ddata->idle_work);
2492
Tony Lindgren684be5a2017-10-13 10:48:40 -07002493 error = pm_runtime_get_sync(ddata->dev);
2494 if (error < 0) {
2495 pm_runtime_put_noidle(ddata->dev);
2496 pm_runtime_disable(ddata->dev);
2497 goto unprepare;
2498 }
2499
2500 of_platform_depopulate(&pdev->dev);
2501
Tony Lindgren684be5a2017-10-13 10:48:40 -07002502 pm_runtime_put_sync(&pdev->dev);
2503 pm_runtime_disable(&pdev->dev);
Tony Lindgren50622362018-04-16 10:20:27 -07002504 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07002505
2506unprepare:
2507 sysc_unprepare(ddata);
2508
2509 return 0;
2510}
2511
Tony Lindgren0eecc632017-10-10 14:23:43 -07002512static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08002513 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
2514 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
2515 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
2516 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
2517 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
2518 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
2519 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
2520 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
2521 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
2522 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
2523 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08002524 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08002525 { .compatible = "ti,sysc-usb-host-fs",
2526 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05302527 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07002528 { },
2529};
2530MODULE_DEVICE_TABLE(of, sysc_match);
2531
2532static struct platform_driver sysc_driver = {
2533 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07002534 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07002535 .driver = {
2536 .name = "ti-sysc",
2537 .of_match_table = sysc_match,
2538 .pm = &sysc_pm_ops,
2539 },
2540};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002541
2542static int __init sysc_init(void)
2543{
2544 bus_register_notifier(&platform_bus_type, &sysc_nb);
2545
2546 return platform_driver_register(&sysc_driver);
2547}
2548module_init(sysc_init);
2549
2550static void __exit sysc_exit(void)
2551{
2552 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
2553 platform_driver_unregister(&sysc_driver);
2554}
2555module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002556
2557MODULE_DESCRIPTION("TI sysc interconnect target driver");
2558MODULE_LICENSE("GPL v2");