blob: 2587a616cee7fb0f6494217ca857608915f6f9de [file] [log] [blame]
Suman Anna54d66222019-08-13 04:13:32 -07001// SPDX-License-Identifier: GPL-2.0
Tony Lindgren0eecc632017-10-10 14:23:43 -07002/*
3 * ti-sysc.c - Texas Instruments sysc interconnect target driver
Tony Lindgren0eecc632017-10-10 14:23:43 -07004 */
5
6#include <linux/io.h>
7#include <linux/clk.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -08008#include <linux/clkdev.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -08009#include <linux/delay.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070010#include <linux/module.h>
11#include <linux/platform_device.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080012#include <linux/pm_domain.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070013#include <linux/pm_runtime.h>
Tony Lindgren50622362018-04-16 10:20:27 -070014#include <linux/reset.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070015#include <linux/of_address.h>
16#include <linux/of_platform.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080017#include <linux/slab.h>
Faiz Abbas596e7952018-07-09 22:18:39 +053018#include <linux/iopoll.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080019
Tony Lindgren70a65242017-12-15 09:41:09 -080020#include <linux/platform_data/ti-sysc.h>
21
22#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070023
Faiz Abbas596e7952018-07-09 22:18:39 +053024#define MAX_MODULE_SOFTRESET_WAIT 10000
25
Tony Lindgren0eecc632017-10-10 14:23:43 -070026static const char * const reg_names[] = { "rev", "sysc", "syss", };
27
28enum sysc_clocks {
29 SYSC_FCK,
30 SYSC_ICK,
Tony Lindgren09dfe582018-04-16 10:25:52 -070031 SYSC_OPTFCK0,
32 SYSC_OPTFCK1,
33 SYSC_OPTFCK2,
34 SYSC_OPTFCK3,
35 SYSC_OPTFCK4,
36 SYSC_OPTFCK5,
37 SYSC_OPTFCK6,
38 SYSC_OPTFCK7,
Tony Lindgren0eecc632017-10-10 14:23:43 -070039 SYSC_MAX_CLOCKS,
40};
41
Tony Lindgrena54275f2019-03-21 11:00:21 -070042static const char * const clock_names[SYSC_MAX_CLOCKS] = {
43 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
44 "opt5", "opt6", "opt7",
45};
Tony Lindgren0eecc632017-10-10 14:23:43 -070046
Tony Lindgrenc5a2de92017-12-15 09:41:23 -080047#define SYSC_IDLEMODE_MASK 3
48#define SYSC_CLOCKACTIVITY_MASK 3
49
Tony Lindgren0eecc632017-10-10 14:23:43 -070050/**
51 * struct sysc - TI sysc interconnect target module registers and capabilities
52 * @dev: struct device pointer
53 * @module_pa: physical address of the interconnect target module
54 * @module_size: size of the interconnect target module
55 * @module_va: virtual address of the interconnect target module
56 * @offsets: register offsets from module base
Suman Annab58056d2019-08-13 04:13:32 -070057 * @mdata: ti-sysc to hwmod translation data for a module
Tony Lindgren0eecc632017-10-10 14:23:43 -070058 * @clocks: clocks used by the interconnect target module
Tony Lindgren09dfe582018-04-16 10:25:52 -070059 * @clock_roles: clock role names for the found clocks
60 * @nr_clocks: number of clocks used by the interconnect target module
Suman Annab58056d2019-08-13 04:13:32 -070061 * @rsts: resets used by the interconnect target module
Tony Lindgren0eecc632017-10-10 14:23:43 -070062 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -080063 * @cap: interconnect target module capabilities
64 * @cfg: interconnect target module configuration
Suman Annab58056d2019-08-13 04:13:32 -070065 * @cookie: data used by legacy platform callbacks
Tony Lindgren566a9b052017-12-15 09:41:19 -080066 * @name: name if available
67 * @revision: interconnect target module revision
Suman Annab58056d2019-08-13 04:13:32 -070068 * @enabled: sysc runtime enabled status
Tony Lindgren62020f22018-02-22 13:59:44 -080069 * @needs_resume: runtime resume needed on resume from suspend
Suman Annab58056d2019-08-13 04:13:32 -070070 * @child_needs_resume: runtime resume needed for child on resume from suspend
71 * @disable_on_idle: status flag used for disabling modules with resets
72 * @idle_work: work structure used to perform delayed idle on a module
Tony Lindgren4e23be42019-06-10 04:48:05 -070073 * @clk_enable_quirk: module specific clock enable quirk
74 * @clk_disable_quirk: module specific clock disable quirk
75 * @reset_done_quirk: module specific reset done quirk
Tony Lindgren0eecc632017-10-10 14:23:43 -070076 */
77struct sysc {
78 struct device *dev;
79 u64 module_pa;
80 u32 module_size;
81 void __iomem *module_va;
82 int offsets[SYSC_MAX_REGS];
Tony Lindgrena3e92e72019-03-21 11:00:21 -070083 struct ti_sysc_module_data *mdata;
Tony Lindgren09dfe582018-04-16 10:25:52 -070084 struct clk **clocks;
85 const char **clock_roles;
86 int nr_clocks;
Tony Lindgren50622362018-04-16 10:20:27 -070087 struct reset_control *rsts;
Tony Lindgren0eecc632017-10-10 14:23:43 -070088 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -080089 const struct sysc_capabilities *cap;
90 struct sysc_config cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -080091 struct ti_sysc_cookie cookie;
Tony Lindgren566a9b052017-12-15 09:41:19 -080092 const char *name;
93 u32 revision;
Tony Lindgren8383e252019-05-27 04:51:56 -070094 unsigned int enabled:1;
95 unsigned int needs_resume:1;
96 unsigned int child_needs_resume:1;
Tony Lindgren76f0f772018-02-23 08:28:45 -080097 struct delayed_work idle_work;
Tony Lindgren4e23be42019-06-10 04:48:05 -070098 void (*clk_enable_quirk)(struct sysc *sysc);
99 void (*clk_disable_quirk)(struct sysc *sysc);
100 void (*reset_done_quirk)(struct sysc *sysc);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700101};
102
Tony Lindgren4014c082018-12-10 14:11:26 -0800103static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
104 bool is_child);
105
Tony Lindgrenb7182b42019-03-21 11:00:21 -0700106static void sysc_write(struct sysc *ddata, int offset, u32 value)
Faiz Abbas596e7952018-07-09 22:18:39 +0530107{
Tony Lindgren5aa91292019-05-27 04:51:53 -0700108 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
109 writew_relaxed(value & 0xffff, ddata->module_va + offset);
110
111 /* Only i2c revision has LO and HI register with stride of 4 */
112 if (ddata->offsets[SYSC_REVISION] >= 0 &&
113 offset == ddata->offsets[SYSC_REVISION]) {
114 u16 hi = value >> 16;
115
116 writew_relaxed(hi, ddata->module_va + offset + 4);
117 }
118
119 return;
120 }
121
Faiz Abbas596e7952018-07-09 22:18:39 +0530122 writel_relaxed(value, ddata->module_va + offset);
123}
124
Tony Lindgren566a9b052017-12-15 09:41:19 -0800125static u32 sysc_read(struct sysc *ddata, int offset)
126{
127 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
128 u32 val;
129
130 val = readw_relaxed(ddata->module_va + offset);
Tony Lindgren5aa91292019-05-27 04:51:53 -0700131
132 /* Only i2c revision has LO and HI register with stride of 4 */
133 if (ddata->offsets[SYSC_REVISION] >= 0 &&
134 offset == ddata->offsets[SYSC_REVISION]) {
135 u16 tmp = readw_relaxed(ddata->module_va + offset + 4);
136
137 val |= tmp << 16;
138 }
Tony Lindgren566a9b052017-12-15 09:41:19 -0800139
140 return val;
141 }
142
143 return readl_relaxed(ddata->module_va + offset);
144}
145
Tony Lindgren09dfe582018-04-16 10:25:52 -0700146static bool sysc_opt_clks_needed(struct sysc *ddata)
147{
148 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
149}
150
Tony Lindgren0eecc632017-10-10 14:23:43 -0700151static u32 sysc_read_revision(struct sysc *ddata)
152{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800153 int offset = ddata->offsets[SYSC_REVISION];
154
155 if (offset < 0)
156 return 0;
157
158 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700159}
160
Tony Lindgrene0db94f2019-05-27 04:51:53 -0700161static u32 sysc_read_sysconfig(struct sysc *ddata)
162{
163 int offset = ddata->offsets[SYSC_SYSCONFIG];
164
165 if (offset < 0)
166 return 0;
167
168 return sysc_read(ddata, offset);
169}
170
171static u32 sysc_read_sysstatus(struct sysc *ddata)
172{
173 int offset = ddata->offsets[SYSC_SYSSTATUS];
174
175 if (offset < 0)
176 return 0;
177
178 return sysc_read(ddata, offset);
179}
180
Tony Lindgrena54275f2019-03-21 11:00:21 -0700181static int sysc_add_named_clock_from_child(struct sysc *ddata,
182 const char *name,
183 const char *optfck_name)
184{
185 struct device_node *np = ddata->dev->of_node;
186 struct device_node *child;
187 struct clk_lookup *cl;
188 struct clk *clock;
189 const char *n;
190
191 if (name)
192 n = name;
193 else
194 n = optfck_name;
195
196 /* Does the clock alias already exist? */
197 clock = of_clk_get_by_name(np, n);
198 if (!IS_ERR(clock)) {
199 clk_put(clock);
200
201 return 0;
202 }
203
204 child = of_get_next_available_child(np, NULL);
205 if (!child)
206 return -ENODEV;
207
208 clock = devm_get_clk_from_child(ddata->dev, child, name);
209 if (IS_ERR(clock))
210 return PTR_ERR(clock);
211
212 /*
213 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
214 * limit for clk_get(). If cl ever needs to be freed, it should be done
215 * with clkdev_drop().
216 */
217 cl = kcalloc(1, sizeof(*cl), GFP_KERNEL);
218 if (!cl)
219 return -ENOMEM;
220
221 cl->con_id = n;
222 cl->dev_id = dev_name(ddata->dev);
223 cl->clk = clock;
224 clkdev_add(cl);
225
226 clk_put(clock);
227
228 return 0;
229}
230
231static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
232{
233 const char *optfck_name;
234 int error, index;
235
236 if (ddata->nr_clocks < SYSC_OPTFCK0)
237 index = SYSC_OPTFCK0;
238 else
239 index = ddata->nr_clocks;
240
241 if (name)
242 optfck_name = name;
243 else
244 optfck_name = clock_names[index];
245
246 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
247 if (error)
248 return error;
249
250 ddata->clock_roles[index] = optfck_name;
251 ddata->nr_clocks++;
252
253 return 0;
254}
255
Tony Lindgren09dfe582018-04-16 10:25:52 -0700256static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700257{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700258 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700259
Tony Lindgren09dfe582018-04-16 10:25:52 -0700260 if (!strncmp(clock_names[SYSC_FCK], name, 3))
261 index = SYSC_FCK;
262 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
263 index = SYSC_ICK;
264
265 if (index < 0) {
266 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700267 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700268 index = i;
269 break;
270 }
271 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700272 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700273
274 if (index < 0) {
275 dev_err(ddata->dev, "clock %s not added\n", name);
276 return index;
277 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700278
279 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
280 if (IS_ERR(ddata->clocks[index])) {
281 if (PTR_ERR(ddata->clocks[index]) == -ENOENT)
282 return 0;
283
284 dev_err(ddata->dev, "clock get error for %s: %li\n",
285 name, PTR_ERR(ddata->clocks[index]));
286
287 return PTR_ERR(ddata->clocks[index]);
288 }
289
290 error = clk_prepare(ddata->clocks[index]);
291 if (error) {
292 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
293 name, error);
294
295 return error;
296 }
297
298 return 0;
299}
300
301static int sysc_get_clocks(struct sysc *ddata)
302{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700303 struct device_node *np = ddata->dev->of_node;
304 struct property *prop;
305 const char *name;
306 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700307
Kees Cook20749052018-06-18 10:45:49 -0700308 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700309 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700310 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700311 GFP_KERNEL);
312 if (!ddata->clock_roles)
313 return -ENOMEM;
314
315 of_property_for_each_string(np, "clock-names", prop, name) {
316 if (!strncmp(clock_names[SYSC_FCK], name, 3))
317 nr_fck++;
318 if (!strncmp(clock_names[SYSC_ICK], name, 3))
319 nr_ick++;
320 ddata->clock_roles[ddata->nr_clocks] = name;
321 ddata->nr_clocks++;
322 }
323
324 if (ddata->nr_clocks < 1)
325 return 0;
326
Tony Lindgrena54275f2019-03-21 11:00:21 -0700327 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
328 error = sysc_init_ext_opt_clock(ddata, NULL);
329 if (error)
330 return error;
331 }
332
Tony Lindgren09dfe582018-04-16 10:25:52 -0700333 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
334 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
335
336 return -EINVAL;
337 }
338
339 if (nr_fck > 1 || nr_ick > 1) {
340 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
341
342 return -EINVAL;
343 }
344
Kees Cook20749052018-06-18 10:45:49 -0700345 ddata->clocks = devm_kcalloc(ddata->dev,
346 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700347 GFP_KERNEL);
348 if (!ddata->clocks)
349 return -ENOMEM;
350
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800351 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
352 const char *name = ddata->clock_roles[i];
353
354 if (!name)
355 continue;
356
357 error = sysc_get_one_clock(ddata, name);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700358 if (error && error != -ENOENT)
359 return error;
360 }
361
362 return 0;
363}
364
Tony Lindgrend8789702019-03-21 11:00:21 -0700365static int sysc_enable_main_clocks(struct sysc *ddata)
366{
367 struct clk *clock;
368 int i, error;
369
370 if (!ddata->clocks)
371 return 0;
372
373 for (i = 0; i < SYSC_OPTFCK0; i++) {
374 clock = ddata->clocks[i];
375
376 /* Main clocks may not have ick */
377 if (IS_ERR_OR_NULL(clock))
378 continue;
379
380 error = clk_enable(clock);
381 if (error)
382 goto err_disable;
383 }
384
385 return 0;
386
387err_disable:
388 for (i--; i >= 0; i--) {
389 clock = ddata->clocks[i];
390
391 /* Main clocks may not have ick */
392 if (IS_ERR_OR_NULL(clock))
393 continue;
394
395 clk_disable(clock);
396 }
397
398 return error;
399}
400
401static void sysc_disable_main_clocks(struct sysc *ddata)
402{
403 struct clk *clock;
404 int i;
405
406 if (!ddata->clocks)
407 return;
408
409 for (i = 0; i < SYSC_OPTFCK0; i++) {
410 clock = ddata->clocks[i];
411 if (IS_ERR_OR_NULL(clock))
412 continue;
413
414 clk_disable(clock);
415 }
416}
417
418static int sysc_enable_opt_clocks(struct sysc *ddata)
419{
420 struct clk *clock;
421 int i, error;
422
423 if (!ddata->clocks)
424 return 0;
425
426 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
427 clock = ddata->clocks[i];
428
429 /* Assume no holes for opt clocks */
430 if (IS_ERR_OR_NULL(clock))
431 return 0;
432
433 error = clk_enable(clock);
434 if (error)
435 goto err_disable;
436 }
437
438 return 0;
439
440err_disable:
441 for (i--; i >= 0; i--) {
442 clock = ddata->clocks[i];
443 if (IS_ERR_OR_NULL(clock))
444 continue;
445
446 clk_disable(clock);
447 }
448
449 return error;
450}
451
452static void sysc_disable_opt_clocks(struct sysc *ddata)
453{
454 struct clk *clock;
455 int i;
456
457 if (!ddata->clocks)
458 return;
459
460 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
461 clock = ddata->clocks[i];
462
463 /* Assume no holes for opt clocks */
464 if (IS_ERR_OR_NULL(clock))
465 return;
466
467 clk_disable(clock);
468 }
469}
470
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700471static void sysc_clkdm_deny_idle(struct sysc *ddata)
472{
473 struct ti_sysc_platform_data *pdata;
474
475 if (ddata->legacy_mode)
476 return;
477
478 pdata = dev_get_platdata(ddata->dev);
479 if (pdata && pdata->clkdm_deny_idle)
480 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
481}
482
483static void sysc_clkdm_allow_idle(struct sysc *ddata)
484{
485 struct ti_sysc_platform_data *pdata;
486
487 if (ddata->legacy_mode)
488 return;
489
490 pdata = dev_get_platdata(ddata->dev);
491 if (pdata && pdata->clkdm_allow_idle)
492 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
493}
494
Tony Lindgren0eecc632017-10-10 14:23:43 -0700495/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700496 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700497 * @ddata: device driver data
498 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700499 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700500 */
501static int sysc_init_resets(struct sysc *ddata)
502{
Tony Lindgren50622362018-04-16 10:20:27 -0700503 ddata->rsts =
Tero Kristobb88b862019-08-07 15:46:05 +0300504 devm_reset_control_get_optional_shared(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700505 if (IS_ERR(ddata->rsts))
506 return PTR_ERR(ddata->rsts);
507
Tony Lindgren50622362018-04-16 10:20:27 -0700508 return 0;
509}
510
511/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700512 * sysc_parse_and_check_child_range - parses module IO region from ranges
513 * @ddata: device driver data
514 *
515 * In general we only need rev, syss, and sysc registers and not the whole
516 * module range. But we do want the offsets for these registers from the
517 * module base. This allows us to check them against the legacy hwmod
518 * platform data. Let's also check the ranges are configured properly.
519 */
520static int sysc_parse_and_check_child_range(struct sysc *ddata)
521{
522 struct device_node *np = ddata->dev->of_node;
523 const __be32 *ranges;
524 u32 nr_addr, nr_size;
525 int len, error;
526
527 ranges = of_get_property(np, "ranges", &len);
528 if (!ranges) {
529 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
530
531 return -ENOENT;
532 }
533
534 len /= sizeof(*ranges);
535
536 if (len < 3) {
537 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
538
539 return -EINVAL;
540 }
541
542 error = of_property_read_u32(np, "#address-cells", &nr_addr);
543 if (error)
544 return -ENOENT;
545
546 error = of_property_read_u32(np, "#size-cells", &nr_size);
547 if (error)
548 return -ENOENT;
549
550 if (nr_addr != 1 || nr_size != 1) {
551 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
552
553 return -EINVAL;
554 }
555
556 ranges++;
557 ddata->module_pa = of_translate_address(np, ranges++);
558 ddata->module_size = be32_to_cpup(ranges);
559
Tony Lindgren0eecc632017-10-10 14:23:43 -0700560 return 0;
561}
562
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800563static struct device_node *stdout_path;
564
565static void sysc_init_stdout_path(struct sysc *ddata)
566{
567 struct device_node *np = NULL;
568 const char *uart;
569
570 if (IS_ERR(stdout_path))
571 return;
572
573 if (stdout_path)
574 return;
575
576 np = of_find_node_by_path("/chosen");
577 if (!np)
578 goto err;
579
580 uart = of_get_property(np, "stdout-path", NULL);
581 if (!uart)
582 goto err;
583
584 np = of_find_node_by_path(uart);
585 if (!np)
586 goto err;
587
588 stdout_path = np;
589
590 return;
591
592err:
593 stdout_path = ERR_PTR(-ENODEV);
594}
595
596static void sysc_check_quirk_stdout(struct sysc *ddata,
597 struct device_node *np)
598{
599 sysc_init_stdout_path(ddata);
600 if (np != stdout_path)
601 return;
602
603 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
604 SYSC_QUIRK_NO_RESET_ON_INIT;
605}
606
Tony Lindgren0eecc632017-10-10 14:23:43 -0700607/**
608 * sysc_check_one_child - check child configuration
609 * @ddata: device driver data
610 * @np: child device node
611 *
612 * Let's avoid messy situations where we have new interconnect target
613 * node but children have "ti,hwmods". These belong to the interconnect
614 * target node and are managed by this driver.
615 */
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530616static void sysc_check_one_child(struct sysc *ddata,
617 struct device_node *np)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700618{
619 const char *name;
620
621 name = of_get_property(np, "ti,hwmods", NULL);
622 if (name)
623 dev_warn(ddata->dev, "really a child ti,hwmods property?");
624
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800625 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800626 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700627}
628
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530629static void sysc_check_children(struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700630{
631 struct device_node *child;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700632
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530633 for_each_child_of_node(ddata->dev->of_node, child)
634 sysc_check_one_child(ddata, child);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700635}
636
Tony Lindgrena7199e22017-12-15 09:41:14 -0800637/*
638 * So far only I2C uses 16-bit read access with clockactivity with revision
639 * in two registers with stride of 4. We can detect this based on the rev
640 * register size to configure things far enough to be able to properly read
641 * the revision register.
642 */
643static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
644{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800645 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800646 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800647}
648
Tony Lindgren0eecc632017-10-10 14:23:43 -0700649/**
650 * sysc_parse_one - parses the interconnect target module registers
651 * @ddata: device driver data
652 * @reg: register to parse
653 */
654static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
655{
656 struct resource *res;
657 const char *name;
658
659 switch (reg) {
660 case SYSC_REVISION:
661 case SYSC_SYSCONFIG:
662 case SYSC_SYSSTATUS:
663 name = reg_names[reg];
664 break;
665 default:
666 return -EINVAL;
667 }
668
669 res = platform_get_resource_byname(to_platform_device(ddata->dev),
670 IORESOURCE_MEM, name);
671 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700672 ddata->offsets[reg] = -ENODEV;
673
674 return 0;
675 }
676
677 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800678 if (reg == SYSC_REVISION)
679 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700680
681 return 0;
682}
683
684static int sysc_parse_registers(struct sysc *ddata)
685{
686 int i, error;
687
688 for (i = 0; i < SYSC_MAX_REGS; i++) {
689 error = sysc_parse_one(ddata, i);
690 if (error)
691 return error;
692 }
693
694 return 0;
695}
696
697/**
698 * sysc_check_registers - check for misconfigured register overlaps
699 * @ddata: device driver data
700 */
701static int sysc_check_registers(struct sysc *ddata)
702{
703 int i, j, nr_regs = 0, nr_matches = 0;
704
705 for (i = 0; i < SYSC_MAX_REGS; i++) {
706 if (ddata->offsets[i] < 0)
707 continue;
708
709 if (ddata->offsets[i] > (ddata->module_size - 4)) {
710 dev_err(ddata->dev, "register outside module range");
711
712 return -EINVAL;
713 }
714
715 for (j = 0; j < SYSC_MAX_REGS; j++) {
716 if (ddata->offsets[j] < 0)
717 continue;
718
719 if (ddata->offsets[i] == ddata->offsets[j])
720 nr_matches++;
721 }
722 nr_regs++;
723 }
724
Tony Lindgren0eecc632017-10-10 14:23:43 -0700725 if (nr_matches > nr_regs) {
726 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
727 nr_regs, nr_matches);
728
729 return -EINVAL;
730 }
731
732 return 0;
733}
734
735/**
736 * syc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700737 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700738 *
739 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700740 * within the interconnect target module range. For example, SGX has
741 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
742 * has them at offset 0x1200 in the CPSW_WR child. Usually the
743 * the interconnect target module registers are at the beginning of
744 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700745 */
746static int sysc_ioremap(struct sysc *ddata)
747{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700748 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700749
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700750 if (ddata->offsets[SYSC_REVISION] < 0 &&
751 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
752 ddata->offsets[SYSC_SYSSTATUS] < 0) {
753 size = ddata->module_size;
754 } else {
755 size = max3(ddata->offsets[SYSC_REVISION],
756 ddata->offsets[SYSC_SYSCONFIG],
757 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700758
Tony Lindgren4e23be42019-06-10 04:48:05 -0700759 if (size < SZ_1K)
760 size = SZ_1K;
761
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700762 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700763 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700764 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700765
Tony Lindgren0eecc632017-10-10 14:23:43 -0700766 ddata->module_va = devm_ioremap(ddata->dev,
767 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700768 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700769 if (!ddata->module_va)
770 return -EIO;
771
772 return 0;
773}
774
775/**
776 * sysc_map_and_check_registers - ioremap and check device registers
777 * @ddata: device driver data
778 */
779static int sysc_map_and_check_registers(struct sysc *ddata)
780{
781 int error;
782
783 error = sysc_parse_and_check_child_range(ddata);
784 if (error)
785 return error;
786
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530787 sysc_check_children(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700788
789 error = sysc_parse_registers(ddata);
790 if (error)
791 return error;
792
793 error = sysc_ioremap(ddata);
794 if (error)
795 return error;
796
797 error = sysc_check_registers(ddata);
798 if (error)
799 return error;
800
801 return 0;
802}
803
804/**
805 * sysc_show_rev - read and show interconnect target module revision
806 * @bufp: buffer to print the information to
807 * @ddata: device driver data
808 */
809static int sysc_show_rev(char *bufp, struct sysc *ddata)
810{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800811 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700812
813 if (ddata->offsets[SYSC_REVISION] < 0)
814 return sprintf(bufp, ":NA");
815
Tony Lindgren566a9b052017-12-15 09:41:19 -0800816 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700817
818 return len;
819}
820
821static int sysc_show_reg(struct sysc *ddata,
822 char *bufp, enum sysc_registers reg)
823{
824 if (ddata->offsets[reg] < 0)
825 return sprintf(bufp, ":NA");
826
827 return sprintf(bufp, ":%x", ddata->offsets[reg]);
828}
829
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800830static int sysc_show_name(char *bufp, struct sysc *ddata)
831{
832 if (!ddata->name)
833 return 0;
834
835 return sprintf(bufp, ":%s", ddata->name);
836}
837
Tony Lindgren0eecc632017-10-10 14:23:43 -0700838/**
839 * sysc_show_registers - show information about interconnect target module
840 * @ddata: device driver data
841 */
842static void sysc_show_registers(struct sysc *ddata)
843{
844 char buf[128];
845 char *bufp = buf;
846 int i;
847
848 for (i = 0; i < SYSC_MAX_REGS; i++)
849 bufp += sysc_show_reg(ddata, bufp, i);
850
851 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800852 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700853
854 dev_dbg(ddata->dev, "%llx:%x%s\n",
855 ddata->module_pa, ddata->module_size,
856 buf);
857}
858
Roger Quadrosd59b6052019-04-08 12:52:39 +0300859#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700860#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +0300861
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700862/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300863static int sysc_enable_module(struct device *dev)
864{
865 struct sysc *ddata;
866 const struct sysc_regbits *regbits;
867 u32 reg, idlemodes, best_mode;
868
869 ddata = dev_get_drvdata(dev);
870 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
871 return 0;
872
Roger Quadrosd59b6052019-04-08 12:52:39 +0300873 regbits = ddata->cap->regbits;
874 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
875
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700876 /* Set CLOCKACTIVITY, we only use it for ick */
877 if (regbits->clkact_shift >= 0 &&
878 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT ||
879 ddata->cfg.sysc_val & BIT(regbits->clkact_shift)))
880 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
881
Roger Quadrosd59b6052019-04-08 12:52:39 +0300882 /* Set SIDLE mode */
883 idlemodes = ddata->cfg.sidlemodes;
884 if (!idlemodes || regbits->sidle_shift < 0)
885 goto set_midle;
886
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700887 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
888 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
889 best_mode = SYSC_IDLE_NO;
890 } else {
891 best_mode = fls(ddata->cfg.sidlemodes) - 1;
892 if (best_mode > SYSC_IDLE_MASK) {
893 dev_err(dev, "%s: invalid sidlemode\n", __func__);
894 return -EINVAL;
895 }
Tony Lindgren6e09f492019-05-27 04:51:55 -0700896
897 /* Set WAKEUP */
898 if (regbits->enwkup_shift >= 0 &&
899 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
900 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +0300901 }
902
903 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
904 reg |= best_mode << regbits->sidle_shift;
905 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
906
907set_midle:
908 /* Set MIDLE mode */
909 idlemodes = ddata->cfg.midlemodes;
910 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -0700911 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +0300912
913 best_mode = fls(ddata->cfg.midlemodes) - 1;
914 if (best_mode > SYSC_IDLE_MASK) {
915 dev_err(dev, "%s: invalid midlemode\n", __func__);
916 return -EINVAL;
917 }
918
919 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
920 reg |= best_mode << regbits->midle_shift;
921 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
922
Tony Lindgreneec26552019-05-27 04:51:54 -0700923set_autoidle:
924 /* Autoidle bit must enabled separately if available */
925 if (regbits->autoidle_shift >= 0 &&
926 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
927 reg |= 1 << regbits->autoidle_shift;
928 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
929 }
930
Roger Quadrosd59b6052019-04-08 12:52:39 +0300931 return 0;
932}
933
934static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
935{
936 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
937 *best_mode = SYSC_IDLE_SMART_WKUP;
938 else if (idlemodes & BIT(SYSC_IDLE_SMART))
939 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -0700940 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +0300941 *best_mode = SYSC_IDLE_FORCE;
942 else
943 return -EINVAL;
944
945 return 0;
946}
947
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700948/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300949static int sysc_disable_module(struct device *dev)
950{
951 struct sysc *ddata;
952 const struct sysc_regbits *regbits;
953 u32 reg, idlemodes, best_mode;
954 int ret;
955
956 ddata = dev_get_drvdata(dev);
957 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
958 return 0;
959
Roger Quadrosd59b6052019-04-08 12:52:39 +0300960 regbits = ddata->cap->regbits;
961 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
962
963 /* Set MIDLE mode */
964 idlemodes = ddata->cfg.midlemodes;
965 if (!idlemodes || regbits->midle_shift < 0)
966 goto set_sidle;
967
968 ret = sysc_best_idle_mode(idlemodes, &best_mode);
969 if (ret) {
970 dev_err(dev, "%s: invalid midlemode\n", __func__);
971 return ret;
972 }
973
974 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
975 reg |= best_mode << regbits->midle_shift;
976 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
977
978set_sidle:
979 /* Set SIDLE mode */
980 idlemodes = ddata->cfg.sidlemodes;
981 if (!idlemodes || regbits->sidle_shift < 0)
982 return 0;
983
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700984 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
985 best_mode = SYSC_IDLE_FORCE;
986 } else {
987 ret = sysc_best_idle_mode(idlemodes, &best_mode);
988 if (ret) {
989 dev_err(dev, "%s: invalid sidlemode\n", __func__);
990 return ret;
991 }
Roger Quadrosd59b6052019-04-08 12:52:39 +0300992 }
993
994 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
995 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -0700996 if (regbits->autoidle_shift >= 0 &&
997 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
998 reg |= 1 << regbits->autoidle_shift;
Roger Quadrosd59b6052019-04-08 12:52:39 +0300999 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
1000
1001 return 0;
1002}
1003
Tony Lindgrenff437282019-03-21 11:00:21 -07001004static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1005 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001006{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001007 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001008 int error;
1009
1010 pdata = dev_get_platdata(ddata->dev);
1011 if (!pdata)
1012 return 0;
1013
1014 if (!pdata->idle_module)
1015 return -ENODEV;
1016
1017 error = pdata->idle_module(dev, &ddata->cookie);
1018 if (error)
1019 dev_err(dev, "%s: could not idle: %i\n",
1020 __func__, error);
1021
Tero Kristo4345f0d2019-08-07 15:46:04 +03001022 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001023
Tony Lindgrenff437282019-03-21 11:00:21 -07001024 return 0;
1025}
1026
1027static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1028 struct sysc *ddata)
1029{
1030 struct ti_sysc_platform_data *pdata;
1031 int error;
1032
Tero Kristo4345f0d2019-08-07 15:46:04 +03001033 reset_control_deassert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001034
Tony Lindgrenff437282019-03-21 11:00:21 -07001035 pdata = dev_get_platdata(ddata->dev);
1036 if (!pdata)
1037 return 0;
1038
1039 if (!pdata->enable_module)
1040 return -ENODEV;
1041
1042 error = pdata->enable_module(dev, &ddata->cookie);
1043 if (error)
1044 dev_err(dev, "%s: could not enable: %i\n",
1045 __func__, error);
1046
1047 return 0;
1048}
1049
1050static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1051{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001052 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001053 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001054
1055 ddata = dev_get_drvdata(dev);
1056
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001057 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001058 return 0;
1059
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001060 sysc_clkdm_deny_idle(ddata);
1061
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001062 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001063 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001064 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001065 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001066 } else {
1067 error = sysc_disable_module(dev);
1068 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001069 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001070 }
1071
Tony Lindgrend8789702019-03-21 11:00:21 -07001072 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001073
Tony Lindgrend8789702019-03-21 11:00:21 -07001074 if (sysc_opt_clks_needed(ddata))
1075 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001076
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001077 ddata->enabled = false;
1078
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001079err_allow_idle:
Tero Kristo4345f0d2019-08-07 15:46:04 +03001080 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001081
Tero Kristob6036312019-08-07 15:46:03 +03001082 sysc_clkdm_allow_idle(ddata);
1083
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001084 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001085}
1086
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001087static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001088{
1089 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001090 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001091
1092 ddata = dev_get_drvdata(dev);
1093
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001094 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001095 return 0;
1096
Tony Lindgren8383e252019-05-27 04:51:56 -07001097
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001098 sysc_clkdm_deny_idle(ddata);
1099
Tero Kristo4345f0d2019-08-07 15:46:04 +03001100 reset_control_deassert(ddata->rsts);
Tero Kristob6036312019-08-07 15:46:03 +03001101
Tony Lindgrend8789702019-03-21 11:00:21 -07001102 if (sysc_opt_clks_needed(ddata)) {
1103 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001104 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001105 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001106 }
1107
Tony Lindgrend8789702019-03-21 11:00:21 -07001108 error = sysc_enable_main_clocks(ddata);
1109 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001110 goto err_opt_clocks;
1111
1112 if (ddata->legacy_mode) {
1113 error = sysc_runtime_resume_legacy(dev, ddata);
1114 if (error)
1115 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001116 } else {
1117 error = sysc_enable_module(dev);
1118 if (error)
1119 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001120 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001121
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001122 ddata->enabled = true;
1123
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001124 sysc_clkdm_allow_idle(ddata);
1125
Tony Lindgrend8789702019-03-21 11:00:21 -07001126 return 0;
1127
1128err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001129 sysc_disable_main_clocks(ddata);
1130err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001131 if (sysc_opt_clks_needed(ddata))
1132 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001133err_allow_idle:
1134 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001135
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001136 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001137}
1138
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001139static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001140{
1141 struct sysc *ddata;
1142
1143 ddata = dev_get_drvdata(dev);
1144
Tony Lindgren40d9f912018-09-24 12:16:54 -07001145 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001146 return 0;
1147
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001148 return pm_runtime_force_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001149}
1150
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001151static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001152{
1153 struct sysc *ddata;
1154
1155 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001156
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_resume(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001161}
1162
Tony Lindgren0eecc632017-10-10 14:23:43 -07001163static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001164 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001165 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1166 sysc_runtime_resume,
1167 NULL)
1168};
1169
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001170/* Module revision register based quirks */
1171struct sysc_revision_quirk {
1172 const char *name;
1173 u32 base;
1174 int rev_offset;
1175 int sysc_offset;
1176 int syss_offset;
1177 u32 revision;
1178 u32 revision_mask;
1179 u32 quirks;
1180};
1181
1182#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1183 optrev_val, optrevmask, optquirkmask) \
1184 { \
1185 .name = (optname), \
1186 .base = (optbase), \
1187 .rev_offset = (optrev), \
1188 .sysc_offset = (optsysc), \
1189 .syss_offset = (optsyss), \
1190 .revision = (optrev_val), \
1191 .revision_mask = (optrevmask), \
1192 .quirks = (optquirkmask), \
1193 }
1194
1195static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1196 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001197 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -07001198 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001199 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
1200 SYSC_QUIRK_LEGACY_IDLE),
1201 SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff,
1202 SYSC_QUIRK_LEGACY_IDLE),
1203 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1204 SYSC_QUIRK_LEGACY_IDLE),
1205 SYSC_QUIRK("smartreflex", 0, -1, 0x24, -1, 0x00000000, 0xffffffff,
1206 SYSC_QUIRK_LEGACY_IDLE),
1207 SYSC_QUIRK("smartreflex", 0, -1, 0x38, -1, 0x00000000, 0xffffffff,
1208 SYSC_QUIRK_LEGACY_IDLE),
1209 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001210 0),
Tony Lindgren8cde5d52018-04-16 10:25:15 -07001211 /* Some timers on omap4 and later */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001212 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x50002100, 0xffffffff,
Tony Lindgren072167d2019-01-29 07:53:47 -08001213 0),
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001214 SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x4fff1301, 0xffff00ff,
Tony Lindgren9bd34c62019-01-22 09:03:08 -08001215 0),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001216 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1217 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001218 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001219 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001220 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001221 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001222 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001223 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001224 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001225
Tony Lindgrena54275f2019-03-21 11:00:21 -07001226 /* Quirks that need to be set based on the module address */
1227 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -1, 0x50000800, 0xffffffff,
1228 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1229 SYSC_QUIRK_SWSUP_SIDLE),
1230
Tony Lindgren4e23be42019-06-10 04:48:05 -07001231 /* Quirks that need to be set based on detected module */
1232 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
1233 SYSC_MODULE_QUIRK_HDQ1W),
1234 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
1235 SYSC_MODULE_QUIRK_HDQ1W),
1236 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
1237 SYSC_MODULE_QUIRK_I2C),
1238 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
1239 SYSC_MODULE_QUIRK_I2C),
1240 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
1241 SYSC_MODULE_QUIRK_I2C),
1242 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
1243 SYSC_MODULE_QUIRK_I2C),
1244 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1245 SYSC_MODULE_QUIRK_WDT),
1246
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001247#ifdef DEBUG
Tony Lindgren1ba30692018-09-24 12:17:05 -07001248 SYSC_QUIRK("adc", 0, 0, 0x10, -1, 0x47300001, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001249 SYSC_QUIRK("atl", 0, 0, -1, -1, 0x0a070100, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001250 SYSC_QUIRK("aess", 0, 0, 0x10, -1, 0x40000000, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001251 SYSC_QUIRK("cm", 0, 0, -1, -1, 0x40000301, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001252 SYSC_QUIRK("control", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001253 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001254 0xffff00f0, 0),
Tony Lindgren89bbc6f2019-07-22 03:44:42 -07001255 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0xa3170504, 0xffffffff, 0),
1256 SYSC_QUIRK("dcan", 0, 0x20, -1, -1, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren13aad512019-03-21 11:00:21 -07001257 SYSC_QUIRK("dmic", 0, 0, 0x10, -1, 0x50010000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001258 SYSC_QUIRK("dwc3", 0, 0, 0x10, -1, 0x500a0200, 0xffffffff, 0),
1259 SYSC_QUIRK("epwmss", 0, 0, 0x4, -1, 0x47400001, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001260 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -1, 0, 0, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001261 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
1262 SYSC_QUIRK("iss", 0, 0, 0x10, -1, 0x40000101, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001263 SYSC_QUIRK("lcdc", 0, 0, 0x54, -1, 0x4f201000, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001264 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44306302, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001265 SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44307b02, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001266 SYSC_QUIRK("mcbsp", 0, -1, 0x8c, -1, 0, 0, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001267 SYSC_QUIRK("mcspi", 0, 0, 0x10, -1, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001268 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001269 SYSC_QUIRK("mailbox", 0, 0, 0x10, -1, 0x00000400, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001270 SYSC_QUIRK("m3", 0, 0, -1, -1, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001271 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001272 SYSC_QUIRK("ocp2scp", 0, 0, -1, -1, 0x50060007, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001273 SYSC_QUIRK("padconf", 0, 0, 0x10, -1, 0x4fff0800, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001274 SYSC_QUIRK("padconf", 0, 0, -1, -1, 0x40001100, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001275 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000100, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001276 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x00004102, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001277 SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000400, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001278 SYSC_QUIRK("scm", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren23731ea2018-09-24 12:17:09 -07001279 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4e8b0100, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001280 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4f000100, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001281 SYSC_QUIRK("scm", 0, 0, -1, -1, 0x40000900, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001282 SYSC_QUIRK("scrm", 0, 0, -1, -1, 0x00000010, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001283 SYSC_QUIRK("sdio", 0, 0, 0x10, -1, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001284 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001285 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001286 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40000902, 0xffffffff, 0),
1287 SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40002903, 0xffffffff, 0),
1288 SYSC_QUIRK("spinlock", 0, 0, 0x10, -1, 0x50020000, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001289 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -1, 0x00000020, 0xffffffff, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001290 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -1, 0x4eb01908, 0xffff00f0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001291 SYSC_QUIRK("timer32k", 0, 0, 0x4, -1, 0x00000060, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001292 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001293 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001294 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001295 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -1, 0x50700101, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001296 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1297 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001298 SYSC_QUIRK("vfpe", 0, 0, 0x104, -1, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001299#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001300};
1301
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001302/*
1303 * Early quirks based on module base and register offsets only that are
1304 * needed before the module revision can be read
1305 */
1306static void sysc_init_early_quirks(struct sysc *ddata)
1307{
1308 const struct sysc_revision_quirk *q;
1309 int i;
1310
1311 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1312 q = &sysc_revision_quirks[i];
1313
1314 if (!q->base)
1315 continue;
1316
1317 if (q->base != ddata->module_pa)
1318 continue;
1319
1320 if (q->rev_offset >= 0 &&
1321 q->rev_offset != ddata->offsets[SYSC_REVISION])
1322 continue;
1323
1324 if (q->sysc_offset >= 0 &&
1325 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1326 continue;
1327
1328 if (q->syss_offset >= 0 &&
1329 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1330 continue;
1331
1332 ddata->name = q->name;
1333 ddata->cfg.quirks |= q->quirks;
1334 }
1335}
1336
1337/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001338static void sysc_init_revision_quirks(struct sysc *ddata)
1339{
1340 const struct sysc_revision_quirk *q;
1341 int i;
1342
1343 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1344 q = &sysc_revision_quirks[i];
1345
1346 if (q->base && q->base != ddata->module_pa)
1347 continue;
1348
1349 if (q->rev_offset >= 0 &&
1350 q->rev_offset != ddata->offsets[SYSC_REVISION])
1351 continue;
1352
1353 if (q->sysc_offset >= 0 &&
1354 q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
1355 continue;
1356
1357 if (q->syss_offset >= 0 &&
1358 q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
1359 continue;
1360
1361 if (q->revision == ddata->revision ||
1362 (q->revision & q->revision_mask) ==
1363 (ddata->revision & q->revision_mask)) {
1364 ddata->name = q->name;
1365 ddata->cfg.quirks |= q->quirks;
1366 }
1367 }
1368}
1369
Tony Lindgren4e23be42019-06-10 04:48:05 -07001370/* 1-wire needs module's internal clocks enabled for reset */
1371static void sysc_clk_enable_quirk_hdq1w(struct sysc *ddata)
1372{
1373 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1374 u16 val;
1375
1376 val = sysc_read(ddata, offset);
1377 val |= BIT(5);
1378 sysc_write(ddata, offset, val);
1379}
1380
1381/* I2C needs extra enable bit toggling for reset */
1382static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1383{
1384 int offset;
1385 u16 val;
1386
1387 /* I2C_CON, omap2/3 is different from omap4 and later */
1388 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1389 offset = 0x24;
1390 else
1391 offset = 0xa4;
1392
1393 /* I2C_EN */
1394 val = sysc_read(ddata, offset);
1395 if (enable)
1396 val |= BIT(15);
1397 else
1398 val &= ~BIT(15);
1399 sysc_write(ddata, offset, val);
1400}
1401
1402static void sysc_clk_enable_quirk_i2c(struct sysc *ddata)
1403{
1404 sysc_clk_quirk_i2c(ddata, true);
1405}
1406
1407static void sysc_clk_disable_quirk_i2c(struct sysc *ddata)
1408{
1409 sysc_clk_quirk_i2c(ddata, false);
1410}
1411
1412/* Watchdog timer needs a disable sequence after reset */
1413static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1414{
1415 int wps, spr, error;
1416 u32 val;
1417
1418 wps = 0x34;
1419 spr = 0x48;
1420
1421 sysc_write(ddata, spr, 0xaaaa);
1422 error = readl_poll_timeout(ddata->module_va + wps, val,
1423 !(val & 0x10), 100,
1424 MAX_MODULE_SOFTRESET_WAIT);
1425 if (error)
1426 dev_warn(ddata->dev, "wdt disable spr failed\n");
1427
1428 sysc_write(ddata, wps, 0x5555);
1429 error = readl_poll_timeout(ddata->module_va + wps, val,
1430 !(val & 0x10), 100,
1431 MAX_MODULE_SOFTRESET_WAIT);
1432 if (error)
1433 dev_warn(ddata->dev, "wdt disable wps failed\n");
1434}
1435
1436static void sysc_init_module_quirks(struct sysc *ddata)
1437{
1438 if (ddata->legacy_mode || !ddata->name)
1439 return;
1440
1441 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
1442 ddata->clk_enable_quirk = sysc_clk_enable_quirk_hdq1w;
1443
1444 return;
1445 }
1446
1447 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
1448 ddata->clk_enable_quirk = sysc_clk_enable_quirk_i2c;
1449 ddata->clk_disable_quirk = sysc_clk_disable_quirk_i2c;
1450
1451 return;
1452 }
1453
1454 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT)
1455 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
1456}
1457
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001458static int sysc_clockdomain_init(struct sysc *ddata)
1459{
1460 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1461 struct clk *fck = NULL, *ick = NULL;
1462 int error;
1463
1464 if (!pdata || !pdata->init_clockdomain)
1465 return 0;
1466
1467 switch (ddata->nr_clocks) {
1468 case 2:
1469 ick = ddata->clocks[SYSC_ICK];
1470 /* fallthrough */
1471 case 1:
1472 fck = ddata->clocks[SYSC_FCK];
1473 break;
1474 case 0:
1475 return 0;
1476 }
1477
1478 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
1479 if (!error || error == -ENODEV)
1480 return 0;
1481
1482 return error;
1483}
1484
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001485/*
1486 * Note that pdata->init_module() typically does a reset first. After
1487 * pdata->init_module() is done, PM runtime can be used for the interconnect
1488 * target module.
1489 */
1490static int sysc_legacy_init(struct sysc *ddata)
1491{
1492 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1493 int error;
1494
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001495 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001496 return 0;
1497
1498 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
1499 if (error == -EEXIST)
1500 error = 0;
1501
1502 return error;
1503}
1504
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001505/**
1506 * sysc_rstctrl_reset_deassert - deassert rstctrl reset
1507 * @ddata: device driver data
1508 * @reset: reset before deassert
1509 *
1510 * A module can have both OCP softreset control and external rstctrl.
1511 * If more complicated rstctrl resets are needed, please handle these
1512 * directly from the child device driver and map only the module reset
1513 * for the parent interconnect target module device.
1514 *
1515 * Automatic reset of the module on init can be skipped with the
1516 * "ti,no-reset-on-init" device tree property.
1517 */
1518static int sysc_rstctrl_reset_deassert(struct sysc *ddata, bool reset)
1519{
Tero Kristobb88b862019-08-07 15:46:05 +03001520 int error;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001521
1522 if (!ddata->rsts)
1523 return 0;
1524
1525 if (reset) {
1526 error = reset_control_assert(ddata->rsts);
1527 if (error)
1528 return error;
1529 }
1530
Tero Kristobb88b862019-08-07 15:46:05 +03001531 reset_control_deassert(ddata->rsts);
1532
1533 return 0;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001534}
1535
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001536/*
1537 * Note that the caller must ensure the interconnect target module is enabled
1538 * before calling reset. Otherwise reset will not complete.
1539 */
Faiz Abbas596e7952018-07-09 22:18:39 +05301540static int sysc_reset(struct sysc *ddata)
1541{
YueHaibingc8a738f2019-06-28 12:10:54 +08001542 int sysc_offset, syss_offset, sysc_val, rstval, error = 0;
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001543 u32 sysc_mask, syss_done;
Faiz Abbas596e7952018-07-09 22:18:39 +05301544
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001545 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
1546 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001547
1548 if (ddata->legacy_mode || sysc_offset < 0 ||
1549 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05301550 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
1551 return 0;
1552
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001553 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05301554
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001555 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
1556 syss_done = 0;
1557 else
1558 syss_done = ddata->cfg.syss_mask;
1559
Tony Lindgren4e23be42019-06-10 04:48:05 -07001560 if (ddata->clk_disable_quirk)
1561 ddata->clk_disable_quirk(ddata);
1562
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001563 sysc_val = sysc_read_sysconfig(ddata);
1564 sysc_val |= sysc_mask;
1565 sysc_write(ddata, sysc_offset, sysc_val);
Faiz Abbas596e7952018-07-09 22:18:39 +05301566
Tony Lindgren4e23be42019-06-10 04:48:05 -07001567 if (ddata->clk_enable_quirk)
1568 ddata->clk_enable_quirk(ddata);
1569
Faiz Abbas596e7952018-07-09 22:18:39 +05301570 /* Poll on reset status */
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001571 if (syss_offset >= 0) {
1572 error = readx_poll_timeout(sysc_read_sysstatus, ddata, rstval,
1573 (rstval & ddata->cfg.syss_mask) ==
1574 syss_done,
1575 100, MAX_MODULE_SOFTRESET_WAIT);
Faiz Abbas596e7952018-07-09 22:18:39 +05301576
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001577 } else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS) {
1578 error = readx_poll_timeout(sysc_read_sysconfig, ddata, rstval,
1579 !(rstval & sysc_mask),
1580 100, MAX_MODULE_SOFTRESET_WAIT);
1581 }
1582
Tony Lindgren4e23be42019-06-10 04:48:05 -07001583 if (ddata->reset_done_quirk)
1584 ddata->reset_done_quirk(ddata);
1585
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001586 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05301587}
1588
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001589/*
1590 * At this point the module is configured enough to read the revision but
1591 * module may not be completely configured yet to use PM runtime. Enable
1592 * all clocks directly during init to configure the quirks needed for PM
1593 * runtime based on the revision register.
1594 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08001595static int sysc_init_module(struct sysc *ddata)
1596{
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001597 int error = 0;
1598 bool manage_clocks = true;
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001599
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001600 error = sysc_rstctrl_reset_deassert(ddata, false);
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -07001601 if (error)
1602 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001603
Tony Lindgren386cb762019-03-22 07:49:30 -07001604 if (ddata->cfg.quirks &
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001605 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))
1606 manage_clocks = false;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001607
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001608 error = sysc_clockdomain_init(ddata);
1609 if (error)
1610 return error;
1611
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001612 if (manage_clocks) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001613 sysc_clkdm_deny_idle(ddata);
1614
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001615 error = sysc_enable_opt_clocks(ddata);
1616 if (error)
1617 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001618
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001619 error = sysc_enable_main_clocks(ddata);
1620 if (error)
1621 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05301622 }
1623
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001624 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
1625 error = sysc_rstctrl_reset_deassert(ddata, true);
1626 if (error)
1627 goto err_main_clocks;
1628 }
1629
Tony Lindgren566a9b052017-12-15 09:41:19 -08001630 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001631 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001632 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001633
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001634 if (ddata->legacy_mode) {
1635 error = sysc_legacy_init(ddata);
1636 if (error)
1637 goto err_main_clocks;
1638 }
1639
1640 if (!ddata->legacy_mode && manage_clocks) {
1641 error = sysc_enable_module(ddata->dev);
1642 if (error)
1643 goto err_main_clocks;
1644 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001645
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001646 error = sysc_reset(ddata);
1647 if (error)
1648 dev_err(ddata->dev, "Reset failed with %d\n", error);
1649
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001650 if (!ddata->legacy_mode && manage_clocks)
1651 sysc_disable_module(ddata->dev);
1652
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001653err_main_clocks:
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001654 if (manage_clocks)
1655 sysc_disable_main_clocks(ddata);
1656err_opt_clocks:
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001657 if (manage_clocks) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001658 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001659 sysc_clkdm_allow_idle(ddata);
1660 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001661
1662 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001663}
1664
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001665static int sysc_init_sysc_mask(struct sysc *ddata)
1666{
1667 struct device_node *np = ddata->dev->of_node;
1668 int error;
1669 u32 val;
1670
1671 error = of_property_read_u32(np, "ti,sysc-mask", &val);
1672 if (error)
1673 return 0;
1674
Tony Lindgrene212abd2019-07-22 03:44:52 -07001675 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001676
1677 return 0;
1678}
1679
1680static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
1681 const char *name)
1682{
1683 struct device_node *np = ddata->dev->of_node;
1684 struct property *prop;
1685 const __be32 *p;
1686 u32 val;
1687
1688 of_property_for_each_u32(np, name, prop, p, val) {
1689 if (val >= SYSC_NR_IDLEMODES) {
1690 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
1691 return -EINVAL;
1692 }
1693 *idlemodes |= (1 << val);
1694 }
1695
1696 return 0;
1697}
1698
1699static int sysc_init_idlemodes(struct sysc *ddata)
1700{
1701 int error;
1702
1703 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
1704 "ti,sysc-midle");
1705 if (error)
1706 return error;
1707
1708 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
1709 "ti,sysc-sidle");
1710 if (error)
1711 return error;
1712
1713 return 0;
1714}
1715
1716/*
1717 * Only some devices on omap4 and later have SYSCONFIG reset done
1718 * bit. We can detect this if there is no SYSSTATUS at all, or the
1719 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
1720 * have multiple bits for the child devices like OHCI and EHCI.
1721 * Depends on SYSC being parsed first.
1722 */
1723static int sysc_init_syss_mask(struct sysc *ddata)
1724{
1725 struct device_node *np = ddata->dev->of_node;
1726 int error;
1727 u32 val;
1728
1729 error = of_property_read_u32(np, "ti,syss-mask", &val);
1730 if (error) {
1731 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
1732 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
1733 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1734 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1735
1736 return 0;
1737 }
1738
1739 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
1740 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
1741
1742 ddata->cfg.syss_mask = val;
1743
1744 return 0;
1745}
1746
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001747/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001748 * Many child device drivers need to have fck and opt clocks available
1749 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001750 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001751static int sysc_child_add_named_clock(struct sysc *ddata,
1752 struct device *child,
1753 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001754{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001755 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001756 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001757 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001758
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001759 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001760 return 0;
1761
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001762 clk = clk_get(child, name);
1763 if (!IS_ERR(clk)) {
1764 clk_put(clk);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001765
1766 return -EEXIST;
1767 }
1768
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001769 clk = clk_get(ddata->dev, name);
1770 if (IS_ERR(clk))
1771 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001772
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07001773 l = clkdev_create(clk, name, dev_name(child));
1774 if (!l)
1775 error = -ENOMEM;
1776
1777 clk_put(clk);
1778
1779 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001780}
1781
Tony Lindgren09dfe582018-04-16 10:25:52 -07001782static int sysc_child_add_clocks(struct sysc *ddata,
1783 struct device *child)
1784{
1785 int i, error;
1786
1787 for (i = 0; i < ddata->nr_clocks; i++) {
1788 error = sysc_child_add_named_clock(ddata,
1789 child,
1790 ddata->clock_roles[i]);
1791 if (error && error != -EEXIST) {
1792 dev_err(ddata->dev, "could not add child clock %s: %i\n",
1793 ddata->clock_roles[i], error);
1794
1795 return error;
1796 }
1797 }
1798
1799 return 0;
1800}
1801
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001802static struct device_type sysc_device_type = {
1803};
1804
1805static struct sysc *sysc_child_to_parent(struct device *dev)
1806{
1807 struct device *parent = dev->parent;
1808
1809 if (!parent || parent->type != &sysc_device_type)
1810 return NULL;
1811
1812 return dev_get_drvdata(parent);
1813}
1814
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001815static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
1816{
1817 struct sysc *ddata;
1818 int error;
1819
1820 ddata = sysc_child_to_parent(dev);
1821
1822 error = pm_generic_runtime_suspend(dev);
1823 if (error)
1824 return error;
1825
1826 if (!ddata->enabled)
1827 return 0;
1828
1829 return sysc_runtime_suspend(ddata->dev);
1830}
1831
1832static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
1833{
1834 struct sysc *ddata;
1835 int error;
1836
1837 ddata = sysc_child_to_parent(dev);
1838
1839 if (!ddata->enabled) {
1840 error = sysc_runtime_resume(ddata->dev);
1841 if (error < 0)
1842 dev_err(ddata->dev,
1843 "%s error: %i\n", __func__, error);
1844 }
1845
1846 return pm_generic_runtime_resume(dev);
1847}
1848
1849#ifdef CONFIG_PM_SLEEP
1850static int sysc_child_suspend_noirq(struct device *dev)
1851{
1852 struct sysc *ddata;
1853 int error;
1854
1855 ddata = sysc_child_to_parent(dev);
1856
Tony Lindgrenef55f822018-04-16 10:27:15 -07001857 dev_dbg(ddata->dev, "%s %s\n", __func__,
1858 ddata->name ? ddata->name : "");
1859
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001860 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001861 if (error) {
1862 dev_err(dev, "%s error at %i: %i\n",
1863 __func__, __LINE__, error);
1864
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001865 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001866 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001867
1868 if (!pm_runtime_status_suspended(dev)) {
1869 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001870 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07001871 dev_dbg(dev, "%s busy at %i: %i\n",
1872 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001873
Tony Lindgren4f3530f2018-08-08 01:07:06 -07001874 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001875 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001876
1877 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07001878 if (error) {
1879 dev_err(dev, "%s error at %i: %i\n",
1880 __func__, __LINE__, error);
1881
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001882 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07001883 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001884
1885 ddata->child_needs_resume = true;
1886 }
1887
1888 return 0;
1889}
1890
1891static int sysc_child_resume_noirq(struct device *dev)
1892{
1893 struct sysc *ddata;
1894 int error;
1895
1896 ddata = sysc_child_to_parent(dev);
1897
Tony Lindgrenef55f822018-04-16 10:27:15 -07001898 dev_dbg(ddata->dev, "%s %s\n", __func__,
1899 ddata->name ? ddata->name : "");
1900
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001901 if (ddata->child_needs_resume) {
1902 ddata->child_needs_resume = false;
1903
1904 error = sysc_runtime_resume(ddata->dev);
1905 if (error)
1906 dev_err(ddata->dev,
1907 "%s runtime resume error: %i\n",
1908 __func__, error);
1909
1910 error = pm_generic_runtime_resume(dev);
1911 if (error)
1912 dev_err(ddata->dev,
1913 "%s generic runtime resume: %i\n",
1914 __func__, error);
1915 }
1916
1917 return pm_generic_resume_noirq(dev);
1918}
1919#endif
1920
Tony Lindgrenb7182b42019-03-21 11:00:21 -07001921static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001922 .ops = {
1923 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
1924 sysc_child_runtime_resume,
1925 NULL)
1926 USE_PLATFORM_PM_SLEEP_OPS
1927 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
1928 sysc_child_resume_noirq)
1929 }
1930};
1931
1932/**
1933 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
1934 * @ddata: device driver data
1935 * @child: child device driver
1936 *
1937 * Allow idle for child devices as done with _od_runtime_suspend().
1938 * Otherwise many child devices will not idle because of the permanent
1939 * parent usecount set in pm_runtime_irq_safe().
1940 *
1941 * Note that the long term solution is to just modify the child device
1942 * drivers to not set pm_runtime_irq_safe() and then this can be just
1943 * dropped.
1944 */
1945static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
1946{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001947 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
1948 dev_pm_domain_set(child, &sysc_child_pm_domain);
1949}
1950
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001951static int sysc_notifier_call(struct notifier_block *nb,
1952 unsigned long event, void *device)
1953{
1954 struct device *dev = device;
1955 struct sysc *ddata;
1956 int error;
1957
1958 ddata = sysc_child_to_parent(dev);
1959 if (!ddata)
1960 return NOTIFY_DONE;
1961
1962 switch (event) {
1963 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07001964 error = sysc_child_add_clocks(ddata, dev);
1965 if (error)
1966 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001967 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08001968 break;
1969 default:
1970 break;
1971 }
1972
1973 return NOTIFY_DONE;
1974}
1975
1976static struct notifier_block sysc_nb = {
1977 .notifier_call = sysc_notifier_call,
1978};
1979
Tony Lindgren566a9b052017-12-15 09:41:19 -08001980/* Device tree configured quirks */
1981struct sysc_dts_quirk {
1982 const char *name;
1983 u32 mask;
1984};
1985
1986static const struct sysc_dts_quirk sysc_dts_quirks[] = {
1987 { .name = "ti,no-idle-on-init",
1988 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
1989 { .name = "ti,no-reset-on-init",
1990 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07001991 { .name = "ti,no-idle",
1992 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08001993};
1994
Tony Lindgren4014c082018-12-10 14:11:26 -08001995static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
1996 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08001997{
Tony Lindgren566a9b052017-12-15 09:41:19 -08001998 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08001999 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002000
2001 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002002 const char *name = sysc_dts_quirks[i].name;
2003
2004 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002005 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002006 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002007
2008 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002009 if (is_child) {
2010 dev_warn(ddata->dev,
2011 "dts flag should be at module level for %s\n",
2012 name);
2013 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002014 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002015}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002016
Tony Lindgren4014c082018-12-10 14:11:26 -08002017static int sysc_init_dts_quirks(struct sysc *ddata)
2018{
2019 struct device_node *np = ddata->dev->of_node;
2020 int error;
2021 u32 val;
2022
2023 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2024
2025 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002026 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2027 if (!error) {
2028 if (val > 255) {
2029 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2030 val);
2031 }
2032
2033 ddata->cfg.srst_udelay = (u8)val;
2034 }
2035
2036 return 0;
2037}
2038
Tony Lindgren0eecc632017-10-10 14:23:43 -07002039static void sysc_unprepare(struct sysc *ddata)
2040{
2041 int i;
2042
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002043 if (!ddata->clocks)
2044 return;
2045
Tony Lindgren0eecc632017-10-10 14:23:43 -07002046 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2047 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2048 clk_unprepare(ddata->clocks[i]);
2049 }
2050}
2051
Tony Lindgren70a65242017-12-15 09:41:09 -08002052/*
2053 * Common sysc register bits found on omap2, also known as type1
2054 */
2055static const struct sysc_regbits sysc_regbits_omap2 = {
2056 .dmadisable_shift = -ENODEV,
2057 .midle_shift = 12,
2058 .sidle_shift = 3,
2059 .clkact_shift = 8,
2060 .emufree_shift = 5,
2061 .enwkup_shift = 2,
2062 .srst_shift = 1,
2063 .autoidle_shift = 0,
2064};
2065
2066static const struct sysc_capabilities sysc_omap2 = {
2067 .type = TI_SYSC_OMAP2,
2068 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2069 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2070 SYSC_OMAP2_AUTOIDLE,
2071 .regbits = &sysc_regbits_omap2,
2072};
2073
2074/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2075static const struct sysc_capabilities sysc_omap2_timer = {
2076 .type = TI_SYSC_OMAP2_TIMER,
2077 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2078 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2079 SYSC_OMAP2_AUTOIDLE,
2080 .regbits = &sysc_regbits_omap2,
2081 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2082};
2083
2084/*
2085 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2086 * with different sidle position
2087 */
2088static const struct sysc_regbits sysc_regbits_omap3_sham = {
2089 .dmadisable_shift = -ENODEV,
2090 .midle_shift = -ENODEV,
2091 .sidle_shift = 4,
2092 .clkact_shift = -ENODEV,
2093 .enwkup_shift = -ENODEV,
2094 .srst_shift = 1,
2095 .autoidle_shift = 0,
2096 .emufree_shift = -ENODEV,
2097};
2098
2099static const struct sysc_capabilities sysc_omap3_sham = {
2100 .type = TI_SYSC_OMAP3_SHAM,
2101 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2102 .regbits = &sysc_regbits_omap3_sham,
2103};
2104
2105/*
2106 * AES register bits found on omap3 and later, a variant of
2107 * sysc_regbits_omap2 with different sidle position
2108 */
2109static const struct sysc_regbits sysc_regbits_omap3_aes = {
2110 .dmadisable_shift = -ENODEV,
2111 .midle_shift = -ENODEV,
2112 .sidle_shift = 6,
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_aes = {
2121 .type = TI_SYSC_OMAP3_AES,
2122 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2123 .regbits = &sysc_regbits_omap3_aes,
2124};
2125
2126/*
2127 * Common sysc register bits found on omap4, also known as type2
2128 */
2129static const struct sysc_regbits sysc_regbits_omap4 = {
2130 .dmadisable_shift = 16,
2131 .midle_shift = 4,
2132 .sidle_shift = 2,
2133 .clkact_shift = -ENODEV,
2134 .enwkup_shift = -ENODEV,
2135 .emufree_shift = 1,
2136 .srst_shift = 0,
2137 .autoidle_shift = -ENODEV,
2138};
2139
2140static const struct sysc_capabilities sysc_omap4 = {
2141 .type = TI_SYSC_OMAP4,
2142 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2143 SYSC_OMAP4_SOFTRESET,
2144 .regbits = &sysc_regbits_omap4,
2145};
2146
2147static const struct sysc_capabilities sysc_omap4_timer = {
2148 .type = TI_SYSC_OMAP4_TIMER,
2149 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2150 SYSC_OMAP4_SOFTRESET,
2151 .regbits = &sysc_regbits_omap4,
2152};
2153
2154/*
2155 * Common sysc register bits found on omap4, also known as type3
2156 */
2157static const struct sysc_regbits sysc_regbits_omap4_simple = {
2158 .dmadisable_shift = -ENODEV,
2159 .midle_shift = 2,
2160 .sidle_shift = 0,
2161 .clkact_shift = -ENODEV,
2162 .enwkup_shift = -ENODEV,
2163 .srst_shift = -ENODEV,
2164 .emufree_shift = -ENODEV,
2165 .autoidle_shift = -ENODEV,
2166};
2167
2168static const struct sysc_capabilities sysc_omap4_simple = {
2169 .type = TI_SYSC_OMAP4_SIMPLE,
2170 .regbits = &sysc_regbits_omap4_simple,
2171};
2172
2173/*
2174 * SmartReflex sysc found on omap34xx
2175 */
2176static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2177 .dmadisable_shift = -ENODEV,
2178 .midle_shift = -ENODEV,
2179 .sidle_shift = -ENODEV,
2180 .clkact_shift = 20,
2181 .enwkup_shift = -ENODEV,
2182 .srst_shift = -ENODEV,
2183 .emufree_shift = -ENODEV,
2184 .autoidle_shift = -ENODEV,
2185};
2186
2187static const struct sysc_capabilities sysc_34xx_sr = {
2188 .type = TI_SYSC_OMAP34XX_SR,
2189 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2190 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002191 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2192 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002193};
2194
2195/*
2196 * SmartReflex sysc found on omap36xx and later
2197 */
2198static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2199 .dmadisable_shift = -ENODEV,
2200 .midle_shift = -ENODEV,
2201 .sidle_shift = 24,
2202 .clkact_shift = -ENODEV,
2203 .enwkup_shift = 26,
2204 .srst_shift = -ENODEV,
2205 .emufree_shift = -ENODEV,
2206 .autoidle_shift = -ENODEV,
2207};
2208
2209static const struct sysc_capabilities sysc_36xx_sr = {
2210 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002211 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002212 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002213 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002214};
2215
2216static const struct sysc_capabilities sysc_omap4_sr = {
2217 .type = TI_SYSC_OMAP4_SR,
2218 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002219 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002220};
2221
2222/*
2223 * McASP register bits found on omap4 and later
2224 */
2225static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2226 .dmadisable_shift = -ENODEV,
2227 .midle_shift = -ENODEV,
2228 .sidle_shift = 0,
2229 .clkact_shift = -ENODEV,
2230 .enwkup_shift = -ENODEV,
2231 .srst_shift = -ENODEV,
2232 .emufree_shift = -ENODEV,
2233 .autoidle_shift = -ENODEV,
2234};
2235
2236static const struct sysc_capabilities sysc_omap4_mcasp = {
2237 .type = TI_SYSC_OMAP4_MCASP,
2238 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002239 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2240};
2241
2242/*
2243 * McASP found on dra7 and later
2244 */
2245static const struct sysc_capabilities sysc_dra7_mcasp = {
2246 .type = TI_SYSC_OMAP4_SIMPLE,
2247 .regbits = &sysc_regbits_omap4_simple,
2248 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002249};
2250
2251/*
2252 * FS USB host found on omap4 and later
2253 */
2254static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2255 .dmadisable_shift = -ENODEV,
2256 .midle_shift = -ENODEV,
2257 .sidle_shift = 24,
2258 .clkact_shift = -ENODEV,
2259 .enwkup_shift = 26,
2260 .srst_shift = -ENODEV,
2261 .emufree_shift = -ENODEV,
2262 .autoidle_shift = -ENODEV,
2263};
2264
2265static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2266 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2267 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2268 .regbits = &sysc_regbits_omap4_usb_host_fs,
2269};
2270
Faiz Abbas7f35e632018-07-09 22:18:38 +05302271static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2272 .dmadisable_shift = -ENODEV,
2273 .midle_shift = -ENODEV,
2274 .sidle_shift = -ENODEV,
2275 .clkact_shift = -ENODEV,
2276 .enwkup_shift = 4,
2277 .srst_shift = 0,
2278 .emufree_shift = -ENODEV,
2279 .autoidle_shift = -ENODEV,
2280};
2281
2282static const struct sysc_capabilities sysc_dra7_mcan = {
2283 .type = TI_SYSC_DRA7_MCAN,
2284 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2285 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002286 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302287};
2288
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002289static int sysc_init_pdata(struct sysc *ddata)
2290{
2291 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002292 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002293
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002294 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002295 return 0;
2296
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002297 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2298 if (!mdata)
2299 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002300
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002301 if (ddata->legacy_mode) {
2302 mdata->name = ddata->legacy_mode;
2303 mdata->module_pa = ddata->module_pa;
2304 mdata->module_size = ddata->module_size;
2305 mdata->offsets = ddata->offsets;
2306 mdata->nr_offsets = SYSC_MAX_REGS;
2307 mdata->cap = ddata->cap;
2308 mdata->cfg = &ddata->cfg;
2309 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002310
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002311 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002312
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002313 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002314}
2315
Tony Lindgren70a65242017-12-15 09:41:09 -08002316static int sysc_init_match(struct sysc *ddata)
2317{
2318 const struct sysc_capabilities *cap;
2319
2320 cap = of_device_get_match_data(ddata->dev);
2321 if (!cap)
2322 return -EINVAL;
2323
2324 ddata->cap = cap;
2325 if (ddata->cap)
2326 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2327
2328 return 0;
2329}
2330
Tony Lindgren76f0f772018-02-23 08:28:45 -08002331static void ti_sysc_idle(struct work_struct *work)
2332{
2333 struct sysc *ddata;
2334
2335 ddata = container_of(work, struct sysc, idle_work.work);
2336
2337 if (pm_runtime_active(ddata->dev))
2338 pm_runtime_put_sync(ddata->dev);
2339}
2340
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002341static const struct of_device_id sysc_match_table[] = {
2342 { .compatible = "simple-bus", },
2343 { /* sentinel */ },
2344};
2345
Tony Lindgren0eecc632017-10-10 14:23:43 -07002346static int sysc_probe(struct platform_device *pdev)
2347{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002348 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002349 struct sysc *ddata;
2350 int error;
2351
2352 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
2353 if (!ddata)
2354 return -ENOMEM;
2355
2356 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002357 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002358
Tony Lindgren70a65242017-12-15 09:41:09 -08002359 error = sysc_init_match(ddata);
2360 if (error)
2361 return error;
2362
Tony Lindgren566a9b052017-12-15 09:41:19 -08002363 error = sysc_init_dts_quirks(ddata);
2364 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002365 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002366
Tony Lindgren0eecc632017-10-10 14:23:43 -07002367 error = sysc_map_and_check_registers(ddata);
2368 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002369 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07002370
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002371 error = sysc_init_sysc_mask(ddata);
2372 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002373 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002374
2375 error = sysc_init_idlemodes(ddata);
2376 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002377 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002378
2379 error = sysc_init_syss_mask(ddata);
2380 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002381 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002382
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002383 error = sysc_init_pdata(ddata);
2384 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002385 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002386
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07002387 sysc_init_early_quirks(ddata);
2388
2389 error = sysc_get_clocks(ddata);
2390 if (error)
2391 return error;
2392
Tony Lindgren50622362018-04-16 10:20:27 -07002393 error = sysc_init_resets(ddata);
2394 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002395 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002396
2397 error = sysc_init_module(ddata);
2398 if (error)
2399 goto unprepare;
2400
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002401 pm_runtime_enable(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002402 error = pm_runtime_get_sync(ddata->dev);
2403 if (error < 0) {
2404 pm_runtime_put_noidle(ddata->dev);
2405 pm_runtime_disable(ddata->dev);
2406 goto unprepare;
2407 }
2408
Tero Kristobb88b862019-08-07 15:46:05 +03002409 /* Balance reset counts */
2410 if (ddata->rsts)
2411 reset_control_assert(ddata->rsts);
2412
Tony Lindgren0eecc632017-10-10 14:23:43 -07002413 sysc_show_registers(ddata);
2414
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002415 ddata->dev->type = &sysc_device_type;
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002416 error = of_platform_populate(ddata->dev->of_node, sysc_match_table,
2417 pdata ? pdata->auxdata : NULL,
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002418 ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002419 if (error)
2420 goto err;
2421
Tony Lindgren76f0f772018-02-23 08:28:45 -08002422 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
2423
2424 /* At least earlycon won't survive without deferred idle */
2425 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE_ON_INIT |
2426 SYSC_QUIRK_NO_RESET_ON_INIT)) {
2427 schedule_delayed_work(&ddata->idle_work, 3000);
2428 } else {
2429 pm_runtime_put(&pdev->dev);
2430 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07002431
2432 return 0;
2433
2434err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07002435 pm_runtime_put_sync(&pdev->dev);
2436 pm_runtime_disable(&pdev->dev);
2437unprepare:
2438 sysc_unprepare(ddata);
2439
2440 return error;
2441}
2442
Tony Lindgren684be5a2017-10-13 10:48:40 -07002443static int sysc_remove(struct platform_device *pdev)
2444{
2445 struct sysc *ddata = platform_get_drvdata(pdev);
2446 int error;
2447
Tony Lindgren76f0f772018-02-23 08:28:45 -08002448 cancel_delayed_work_sync(&ddata->idle_work);
2449
Tony Lindgren684be5a2017-10-13 10:48:40 -07002450 error = pm_runtime_get_sync(ddata->dev);
2451 if (error < 0) {
2452 pm_runtime_put_noidle(ddata->dev);
2453 pm_runtime_disable(ddata->dev);
2454 goto unprepare;
2455 }
2456
2457 of_platform_depopulate(&pdev->dev);
2458
Tony Lindgren684be5a2017-10-13 10:48:40 -07002459 pm_runtime_put_sync(&pdev->dev);
2460 pm_runtime_disable(&pdev->dev);
Tony Lindgren50622362018-04-16 10:20:27 -07002461 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07002462
2463unprepare:
2464 sysc_unprepare(ddata);
2465
2466 return 0;
2467}
2468
Tony Lindgren0eecc632017-10-10 14:23:43 -07002469static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08002470 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
2471 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
2472 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
2473 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
2474 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
2475 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
2476 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
2477 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
2478 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
2479 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
2480 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08002481 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08002482 { .compatible = "ti,sysc-usb-host-fs",
2483 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05302484 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07002485 { },
2486};
2487MODULE_DEVICE_TABLE(of, sysc_match);
2488
2489static struct platform_driver sysc_driver = {
2490 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07002491 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07002492 .driver = {
2493 .name = "ti-sysc",
2494 .of_match_table = sysc_match,
2495 .pm = &sysc_pm_ops,
2496 },
2497};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002498
2499static int __init sysc_init(void)
2500{
2501 bus_register_notifier(&platform_bus_type, &sysc_nb);
2502
2503 return platform_driver_register(&sysc_driver);
2504}
2505module_init(sysc_init);
2506
2507static void __exit sysc_exit(void)
2508{
2509 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
2510 platform_driver_unregister(&sysc_driver);
2511}
2512module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002513
2514MODULE_DESCRIPTION("TI sysc interconnect target driver");
2515MODULE_LICENSE("GPL v2");