blob: 542dd9dbd0355da0f61ba3b7435c83cdbd9492cf [file] [log] [blame]
Tero Kristo0a84a912011-12-16 14:36:58 -07001/*
2 * OMAP2+ common Power & Reset Management (PRM) IP block functions
3 *
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Tero Kristo <t-kristo@ti.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 *
12 * For historical purposes, the API used to configure the PRM
13 * interrupt handler refers to it as the "PRCM interrupt." The
14 * underlying registers are located in the PRM on OMAP3/4.
15 *
16 * XXX This code should eventually be moved to a PRM driver.
17 */
18
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/io.h>
23#include <linux/irq.h>
24#include <linux/interrupt.h>
25#include <linux/slab.h>
Tero Kristo943a63a2013-10-25 15:28:11 +030026#include <linux/of.h>
27#include <linux/of_address.h>
28#include <linux/clk-provider.h>
29#include <linux/clk/ti.h>
Tero Kristo0a84a912011-12-16 14:36:58 -070030
Tony Lindgren30a69ef2013-10-10 15:45:13 -070031#include "soc.h"
Tero Kristo0a84a912011-12-16 14:36:58 -070032#include "prm2xxx_3xxx.h"
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -060033#include "prm2xxx.h"
34#include "prm3xxx.h"
Tero Kristo0a84a912011-12-16 14:36:58 -070035#include "prm44xx.h"
Paul Walmsleyd9a16f92012-10-29 20:57:39 -060036#include "common.h"
Tero Kristo943a63a2013-10-25 15:28:11 +030037#include "clock.h"
Tero Kristo3dbb0482014-12-16 18:20:54 +020038#include "cm.h"
39#include "control.h"
Tero Kristo0a84a912011-12-16 14:36:58 -070040
41/*
42 * OMAP_PRCM_MAX_NR_PENDING_REG: maximum number of PRM_IRQ*_MPU regs
43 * XXX this is technically not needed, since
44 * omap_prcm_register_chain_handler() could allocate this based on the
45 * actual amount of memory needed for the SoC
46 */
47#define OMAP_PRCM_MAX_NR_PENDING_REG 2
48
49/*
50 * prcm_irq_chips: an array of all of the "generic IRQ chips" in use
51 * by the PRCM interrupt handler code. There will be one 'chip' per
52 * PRM_{IRQSTATUS,IRQENABLE}_MPU register pair. (So OMAP3 will have
53 * one "chip" and OMAP4 will have two.)
54 */
55static struct irq_chip_generic **prcm_irq_chips;
56
57/*
58 * prcm_irq_setup: the PRCM IRQ parameters for the hardware the code
59 * is currently running on. Defined and passed by initialization code
60 * that calls omap_prcm_register_chain_handler().
61 */
62static struct omap_prcm_irq_setup *prcm_irq_setup;
63
Paul Walmsleyd9a16f92012-10-29 20:57:39 -060064/* prm_base: base virtual address of the PRM IP block */
65void __iomem *prm_base;
66
Tero Kristo2541d152014-03-31 18:15:44 +030067u16 prm_features;
68
Paul Walmsleye24c3572012-10-21 01:01:11 -060069/*
70 * prm_ll_data: function pointers to SoC-specific implementations of
71 * common PRM functions
72 */
73static struct prm_ll_data null_prm_ll_data;
74static struct prm_ll_data *prm_ll_data = &null_prm_ll_data;
75
Tero Kristo0a84a912011-12-16 14:36:58 -070076/* Private functions */
77
78/*
79 * Move priority events from events to priority_events array
80 */
81static void omap_prcm_events_filter_priority(unsigned long *events,
82 unsigned long *priority_events)
83{
84 int i;
85
86 for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
87 priority_events[i] =
88 events[i] & prcm_irq_setup->priority_mask[i];
89 events[i] ^= priority_events[i];
90 }
91}
92
93/*
94 * PRCM Interrupt Handler
95 *
96 * This is a common handler for the OMAP PRCM interrupts. Pending
97 * interrupts are detected by a call to prcm_pending_events and
98 * dispatched accordingly. Clearing of the wakeup events should be
99 * done by the SoC specific individual handlers.
100 */
101static void omap_prcm_irq_handler(unsigned int irq, struct irq_desc *desc)
102{
103 unsigned long pending[OMAP_PRCM_MAX_NR_PENDING_REG];
104 unsigned long priority_pending[OMAP_PRCM_MAX_NR_PENDING_REG];
105 struct irq_chip *chip = irq_desc_get_chip(desc);
106 unsigned int virtirq;
Venkatraman Sb56f2cb2012-06-25 15:56:39 +0530107 int nr_irq = prcm_irq_setup->nr_regs * 32;
Tero Kristo0a84a912011-12-16 14:36:58 -0700108
109 /*
Tero Kristo91285b62011-12-16 14:36:58 -0700110 * If we are suspended, mask all interrupts from PRCM level,
111 * this does not ack them, and they will be pending until we
112 * re-enable the interrupts, at which point the
113 * omap_prcm_irq_handler will be executed again. The
114 * _save_and_clear_irqen() function must ensure that the PRM
115 * write to disable all IRQs has reached the PRM before
116 * returning, or spurious PRCM interrupts may occur during
117 * suspend.
118 */
119 if (prcm_irq_setup->suspended) {
120 prcm_irq_setup->save_and_clear_irqen(prcm_irq_setup->saved_mask);
121 prcm_irq_setup->suspend_save_flag = true;
122 }
123
124 /*
Tero Kristo0a84a912011-12-16 14:36:58 -0700125 * Loop until all pending irqs are handled, since
126 * generic_handle_irq() can cause new irqs to come
127 */
Tero Kristo91285b62011-12-16 14:36:58 -0700128 while (!prcm_irq_setup->suspended) {
Tero Kristo0a84a912011-12-16 14:36:58 -0700129 prcm_irq_setup->read_pending_irqs(pending);
130
131 /* No bit set, then all IRQs are handled */
Venkatraman Sb56f2cb2012-06-25 15:56:39 +0530132 if (find_first_bit(pending, nr_irq) >= nr_irq)
Tero Kristo0a84a912011-12-16 14:36:58 -0700133 break;
134
135 omap_prcm_events_filter_priority(pending, priority_pending);
136
137 /*
138 * Loop on all currently pending irqs so that new irqs
139 * cannot starve previously pending irqs
140 */
141
142 /* Serve priority events first */
Venkatraman Sb56f2cb2012-06-25 15:56:39 +0530143 for_each_set_bit(virtirq, priority_pending, nr_irq)
Tero Kristo0a84a912011-12-16 14:36:58 -0700144 generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
145
146 /* Serve normal events next */
Venkatraman Sb56f2cb2012-06-25 15:56:39 +0530147 for_each_set_bit(virtirq, pending, nr_irq)
Tero Kristo0a84a912011-12-16 14:36:58 -0700148 generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
149 }
150 if (chip->irq_ack)
151 chip->irq_ack(&desc->irq_data);
152 if (chip->irq_eoi)
153 chip->irq_eoi(&desc->irq_data);
154 chip->irq_unmask(&desc->irq_data);
155
156 prcm_irq_setup->ocp_barrier(); /* avoid spurious IRQs */
157}
158
159/* Public functions */
160
161/**
162 * omap_prcm_event_to_irq - given a PRCM event name, returns the
163 * corresponding IRQ on which the handler should be registered
164 * @name: name of the PRCM interrupt bit to look up - see struct omap_prcm_irq
165 *
166 * Returns the Linux internal IRQ ID corresponding to @name upon success,
167 * or -ENOENT upon failure.
168 */
169int omap_prcm_event_to_irq(const char *name)
170{
171 int i;
172
173 if (!prcm_irq_setup || !name)
174 return -ENOENT;
175
176 for (i = 0; i < prcm_irq_setup->nr_irqs; i++)
177 if (!strcmp(prcm_irq_setup->irqs[i].name, name))
178 return prcm_irq_setup->base_irq +
179 prcm_irq_setup->irqs[i].offset;
180
181 return -ENOENT;
182}
183
184/**
185 * omap_prcm_irq_cleanup - reverses memory allocated and other steps
186 * done by omap_prcm_register_chain_handler()
187 *
188 * No return value.
189 */
190void omap_prcm_irq_cleanup(void)
191{
192 int i;
193
194 if (!prcm_irq_setup) {
195 pr_err("PRCM: IRQ handler not initialized; cannot cleanup\n");
196 return;
197 }
198
199 if (prcm_irq_chips) {
200 for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
201 if (prcm_irq_chips[i])
202 irq_remove_generic_chip(prcm_irq_chips[i],
203 0xffffffff, 0, 0);
204 prcm_irq_chips[i] = NULL;
205 }
206 kfree(prcm_irq_chips);
207 prcm_irq_chips = NULL;
208 }
209
Tero Kristo91285b62011-12-16 14:36:58 -0700210 kfree(prcm_irq_setup->saved_mask);
211 prcm_irq_setup->saved_mask = NULL;
212
Tero Kristo0a84a912011-12-16 14:36:58 -0700213 kfree(prcm_irq_setup->priority_mask);
214 prcm_irq_setup->priority_mask = NULL;
215
216 irq_set_chained_handler(prcm_irq_setup->irq, NULL);
217
218 if (prcm_irq_setup->base_irq > 0)
219 irq_free_descs(prcm_irq_setup->base_irq,
220 prcm_irq_setup->nr_regs * 32);
221 prcm_irq_setup->base_irq = 0;
222}
223
Tero Kristo91285b62011-12-16 14:36:58 -0700224void omap_prcm_irq_prepare(void)
225{
226 prcm_irq_setup->suspended = true;
227}
228
229void omap_prcm_irq_complete(void)
230{
231 prcm_irq_setup->suspended = false;
232
233 /* If we have not saved the masks, do not attempt to restore */
234 if (!prcm_irq_setup->suspend_save_flag)
235 return;
236
237 prcm_irq_setup->suspend_save_flag = false;
238
239 /*
240 * Re-enable all masked PRCM irq sources, this causes the PRCM
241 * interrupt to fire immediately if the events were masked
242 * previously in the chain handler
243 */
244 prcm_irq_setup->restore_irqen(prcm_irq_setup->saved_mask);
245}
246
Tero Kristo0a84a912011-12-16 14:36:58 -0700247/**
248 * omap_prcm_register_chain_handler - initializes the prcm chained interrupt
249 * handler based on provided parameters
250 * @irq_setup: hardware data about the underlying PRM/PRCM
251 *
252 * Set up the PRCM chained interrupt handler on the PRCM IRQ. Sets up
253 * one generic IRQ chip per PRM interrupt status/enable register pair.
254 * Returns 0 upon success, -EINVAL if called twice or if invalid
255 * arguments are passed, or -ENOMEM on any other error.
256 */
257int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup)
258{
Paul Walmsleyeeb37112012-04-13 06:34:32 -0600259 int nr_regs;
Tero Kristo0a84a912011-12-16 14:36:58 -0700260 u32 mask[OMAP_PRCM_MAX_NR_PENDING_REG];
261 int offset, i;
262 struct irq_chip_generic *gc;
263 struct irq_chip_type *ct;
264
265 if (!irq_setup)
266 return -EINVAL;
267
Paul Walmsleyeeb37112012-04-13 06:34:32 -0600268 nr_regs = irq_setup->nr_regs;
269
Tero Kristo0a84a912011-12-16 14:36:58 -0700270 if (prcm_irq_setup) {
271 pr_err("PRCM: already initialized; won't reinitialize\n");
272 return -EINVAL;
273 }
274
275 if (nr_regs > OMAP_PRCM_MAX_NR_PENDING_REG) {
276 pr_err("PRCM: nr_regs too large\n");
277 return -EINVAL;
278 }
279
280 prcm_irq_setup = irq_setup;
281
282 prcm_irq_chips = kzalloc(sizeof(void *) * nr_regs, GFP_KERNEL);
Tero Kristo91285b62011-12-16 14:36:58 -0700283 prcm_irq_setup->saved_mask = kzalloc(sizeof(u32) * nr_regs, GFP_KERNEL);
Tero Kristo0a84a912011-12-16 14:36:58 -0700284 prcm_irq_setup->priority_mask = kzalloc(sizeof(u32) * nr_regs,
285 GFP_KERNEL);
286
Tero Kristo91285b62011-12-16 14:36:58 -0700287 if (!prcm_irq_chips || !prcm_irq_setup->saved_mask ||
288 !prcm_irq_setup->priority_mask) {
Tero Kristo0a84a912011-12-16 14:36:58 -0700289 pr_err("PRCM: kzalloc failed\n");
290 goto err;
291 }
292
293 memset(mask, 0, sizeof(mask));
294
295 for (i = 0; i < irq_setup->nr_irqs; i++) {
296 offset = irq_setup->irqs[i].offset;
297 mask[offset >> 5] |= 1 << (offset & 0x1f);
298 if (irq_setup->irqs[i].priority)
299 irq_setup->priority_mask[offset >> 5] |=
300 1 << (offset & 0x1f);
301 }
302
303 irq_set_chained_handler(irq_setup->irq, omap_prcm_irq_handler);
304
305 irq_setup->base_irq = irq_alloc_descs(-1, 0, irq_setup->nr_regs * 32,
306 0);
307
308 if (irq_setup->base_irq < 0) {
309 pr_err("PRCM: failed to allocate irq descs: %d\n",
310 irq_setup->base_irq);
311 goto err;
312 }
313
Ming Lei4ba7c3c2012-03-22 09:23:37 +0800314 for (i = 0; i < irq_setup->nr_regs; i++) {
Tero Kristo0a84a912011-12-16 14:36:58 -0700315 gc = irq_alloc_generic_chip("PRCM", 1,
316 irq_setup->base_irq + i * 32, prm_base,
317 handle_level_irq);
318
319 if (!gc) {
320 pr_err("PRCM: failed to allocate generic chip\n");
321 goto err;
322 }
323 ct = gc->chip_types;
324 ct->chip.irq_ack = irq_gc_ack_set_bit;
325 ct->chip.irq_mask = irq_gc_mask_clr_bit;
326 ct->chip.irq_unmask = irq_gc_mask_set_bit;
327
328 ct->regs.ack = irq_setup->ack + i * 4;
329 ct->regs.mask = irq_setup->mask + i * 4;
330
331 irq_setup_generic_chip(gc, mask[i], 0, IRQ_NOREQUEST, 0);
332 prcm_irq_chips[i] = gc;
333 }
334
Tony Lindgren30a69ef2013-10-10 15:45:13 -0700335 if (of_have_populated_dt()) {
336 int irq = omap_prcm_event_to_irq("io");
Tero Kristo81243652014-03-31 18:15:43 +0300337 omap_pcs_legacy_init(irq, irq_setup->reconfigure_io_chain);
Tony Lindgren30a69ef2013-10-10 15:45:13 -0700338 }
339
Tero Kristo0a84a912011-12-16 14:36:58 -0700340 return 0;
341
342err:
343 omap_prcm_irq_cleanup();
344 return -ENOMEM;
345}
R Sricharan3f4990f2012-07-04 05:04:00 -0600346
Paul Walmsleye24c3572012-10-21 01:01:11 -0600347/**
Paul Walmsleyd9a16f92012-10-29 20:57:39 -0600348 * omap2_set_globals_prm - set the PRM base address (for early use)
349 * @prm: PRM base virtual address
350 *
351 * XXX Will be replaced when the PRM/CM drivers are completed.
R Sricharan3f4990f2012-07-04 05:04:00 -0600352 */
Paul Walmsleyd9a16f92012-10-29 20:57:39 -0600353void __init omap2_set_globals_prm(void __iomem *prm)
R Sricharan3f4990f2012-07-04 05:04:00 -0600354{
Paul Walmsleyd9a16f92012-10-29 20:57:39 -0600355 prm_base = prm;
356}
357
358/**
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600359 * prm_read_reset_sources - return the sources of the SoC's last reset
360 *
361 * Return a u32 bitmask representing the reset sources that caused the
362 * SoC to reset. The low-level per-SoC functions called by this
363 * function remap the SoC-specific reset source bits into an
364 * OMAP-common set of reset source bits, defined in
365 * arch/arm/mach-omap2/prm.h. Returns the standardized reset source
366 * u32 bitmask from the hardware upon success, or returns (1 <<
367 * OMAP_UNKNOWN_RST_SRC_ID_SHIFT) if no low-level read_reset_sources()
368 * function was registered.
R Sricharan3f4990f2012-07-04 05:04:00 -0600369 */
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600370u32 prm_read_reset_sources(void)
R Sricharan3f4990f2012-07-04 05:04:00 -0600371{
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600372 u32 ret = 1 << OMAP_UNKNOWN_RST_SRC_ID_SHIFT;
373
374 if (prm_ll_data->read_reset_sources)
375 ret = prm_ll_data->read_reset_sources();
376 else
377 WARN_ONCE(1, "prm: %s: no mapping function defined for reset sources\n", __func__);
378
379 return ret;
380}
381
382/**
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -0700383 * prm_was_any_context_lost_old - was device context lost? (old API)
384 * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
385 * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
386 * @idx: CONTEXT register offset
387 *
388 * Return 1 if any bits were set in the *_CONTEXT_* register
389 * identified by (@part, @inst, @idx), which means that some context
390 * was lost for that module; otherwise, return 0. XXX Deprecated;
391 * callers need to use a less-SoC-dependent way to identify hardware
392 * IP blocks.
393 */
394bool prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
395{
396 bool ret = true;
397
398 if (prm_ll_data->was_any_context_lost_old)
399 ret = prm_ll_data->was_any_context_lost_old(part, inst, idx);
400 else
401 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
402 __func__);
403
404 return ret;
405}
406
407/**
408 * prm_clear_context_lost_flags_old - clear context loss flags (old API)
409 * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
410 * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
411 * @idx: CONTEXT register offset
412 *
413 * Clear hardware context loss bits for the module identified by
414 * (@part, @inst, @idx). No return value. XXX Deprecated; callers
415 * need to use a less-SoC-dependent way to identify hardware IP
416 * blocks.
417 */
418void prm_clear_context_loss_flags_old(u8 part, s16 inst, u16 idx)
419{
420 if (prm_ll_data->clear_context_loss_flags_old)
421 prm_ll_data->clear_context_loss_flags_old(part, inst, idx);
422 else
423 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
424 __func__);
425}
426
427/**
Tero Kristoefd44dc2014-10-27 08:39:24 -0700428 * omap_prm_assert_hardreset - assert hardreset for an IP block
429 * @shift: register bit shift corresponding to the reset line
430 * @part: PRM partition
431 * @prm_mod: PRM submodule base or instance offset
432 * @offset: register offset
433 *
434 * Asserts a hardware reset line for an IP block.
435 */
436int omap_prm_assert_hardreset(u8 shift, u8 part, s16 prm_mod, u16 offset)
437{
438 if (!prm_ll_data->assert_hardreset) {
439 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
440 __func__);
441 return -EINVAL;
442 }
443
444 return prm_ll_data->assert_hardreset(shift, part, prm_mod, offset);
445}
446
447/**
Tero Kristo37fb59d2014-10-27 08:39:25 -0700448 * omap_prm_deassert_hardreset - deassert hardreset for an IP block
449 * @shift: register bit shift corresponding to the reset line
450 * @st_shift: reset status bit shift corresponding to the reset line
451 * @part: PRM partition
452 * @prm_mod: PRM submodule base or instance offset
453 * @offset: register offset
454 * @st_offset: status register offset
455 *
456 * Deasserts a hardware reset line for an IP block.
457 */
458int omap_prm_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 prm_mod,
459 u16 offset, u16 st_offset)
460{
461 if (!prm_ll_data->deassert_hardreset) {
462 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
463 __func__);
464 return -EINVAL;
465 }
466
467 return prm_ll_data->deassert_hardreset(shift, st_shift, part, prm_mod,
468 offset, st_offset);
469}
470
471/**
Tero Kristo1bc28b32014-10-27 08:39:25 -0700472 * omap_prm_is_hardreset_asserted - check the hardreset status for an IP block
473 * @shift: register bit shift corresponding to the reset line
474 * @part: PRM partition
475 * @prm_mod: PRM submodule base or instance offset
476 * @offset: register offset
477 *
478 * Checks if a hardware reset line for an IP block is enabled or not.
479 */
480int omap_prm_is_hardreset_asserted(u8 shift, u8 part, s16 prm_mod, u16 offset)
481{
482 if (!prm_ll_data->is_hardreset_asserted) {
483 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
484 __func__);
485 return -EINVAL;
486 }
487
488 return prm_ll_data->is_hardreset_asserted(shift, part, prm_mod, offset);
489}
490
491/**
Tero Kristo4984eea2014-10-27 08:39:26 -0700492 * omap_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
493 *
494 * Clear any previously-latched I/O wakeup events and ensure that the
495 * I/O wakeup gates are aligned with the current mux settings.
496 * Calls SoC specific I/O chain reconfigure function if available,
497 * otherwise does nothing.
498 */
499void omap_prm_reconfigure_io_chain(void)
500{
501 if (!prcm_irq_setup || !prcm_irq_setup->reconfigure_io_chain)
502 return;
503
504 prcm_irq_setup->reconfigure_io_chain();
505}
506
507/**
Tero Kristo61c86212014-10-27 08:39:26 -0700508 * omap_prm_reset_system - trigger global SW reset
509 *
510 * Triggers SoC specific global warm reset to reboot the device.
511 */
512void omap_prm_reset_system(void)
513{
514 if (!prm_ll_data->reset_system) {
515 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
516 __func__);
517 return;
518 }
519
520 prm_ll_data->reset_system();
521
522 while (1)
523 cpu_relax();
524}
525
526/**
Paul Walmsleye24c3572012-10-21 01:01:11 -0600527 * prm_register - register per-SoC low-level data with the PRM
528 * @pld: low-level per-SoC OMAP PRM data & function pointers to register
529 *
530 * Register per-SoC low-level OMAP PRM data and function pointers with
531 * the OMAP PRM common interface. The caller must keep the data
532 * pointed to by @pld valid until it calls prm_unregister() and
533 * it returns successfully. Returns 0 upon success, -EINVAL if @pld
534 * is NULL, or -EEXIST if prm_register() has already been called
535 * without an intervening prm_unregister().
536 */
537int prm_register(struct prm_ll_data *pld)
538{
539 if (!pld)
540 return -EINVAL;
541
542 if (prm_ll_data != &null_prm_ll_data)
543 return -EEXIST;
544
545 prm_ll_data = pld;
546
R Sricharan3f4990f2012-07-04 05:04:00 -0600547 return 0;
548}
549
Paul Walmsleye24c3572012-10-21 01:01:11 -0600550/**
551 * prm_unregister - unregister per-SoC low-level data & function pointers
552 * @pld: low-level per-SoC OMAP PRM data & function pointers to unregister
553 *
554 * Unregister per-SoC low-level OMAP PRM data and function pointers
555 * that were previously registered with prm_register(). The
556 * caller may not destroy any of the data pointed to by @pld until
557 * this function returns successfully. Returns 0 upon success, or
558 * -EINVAL if @pld is NULL or if @pld does not match the struct
559 * prm_ll_data * previously registered by prm_register().
560 */
561int prm_unregister(struct prm_ll_data *pld)
R Sricharan3f4990f2012-07-04 05:04:00 -0600562{
Paul Walmsleye24c3572012-10-21 01:01:11 -0600563 if (!pld || prm_ll_data != pld)
564 return -EINVAL;
R Sricharan3f4990f2012-07-04 05:04:00 -0600565
Paul Walmsleye24c3572012-10-21 01:01:11 -0600566 prm_ll_data = &null_prm_ll_data;
567
R Sricharan3f4990f2012-07-04 05:04:00 -0600568 return 0;
569}
Tero Kristo943a63a2013-10-25 15:28:11 +0300570
Uwe Kleine-König31957602014-09-10 10:26:17 +0200571static const struct of_device_id omap_prcm_dt_match_table[] = {
Tero Kristo943a63a2013-10-25 15:28:11 +0300572 { .compatible = "ti,am3-prcm" },
573 { .compatible = "ti,am3-scrm" },
574 { .compatible = "ti,am4-prcm" },
575 { .compatible = "ti,am4-scrm" },
Tero Kristoee200112014-02-25 09:21:39 +0200576 { .compatible = "ti,omap2-prcm" },
577 { .compatible = "ti,omap2-scrm" },
Tero Kristo943a63a2013-10-25 15:28:11 +0300578 { .compatible = "ti,omap3-prm" },
579 { .compatible = "ti,omap3-cm" },
580 { .compatible = "ti,omap3-scrm" },
581 { .compatible = "ti,omap4-cm1" },
582 { .compatible = "ti,omap4-prm" },
583 { .compatible = "ti,omap4-cm2" },
584 { .compatible = "ti,omap4-scrm" },
585 { .compatible = "ti,omap5-prm" },
586 { .compatible = "ti,omap5-cm-core-aon" },
587 { .compatible = "ti,omap5-scrm" },
588 { .compatible = "ti,omap5-cm-core" },
589 { .compatible = "ti,dra7-prm" },
590 { .compatible = "ti,dra7-cm-core-aon" },
591 { .compatible = "ti,dra7-cm-core" },
592 { }
593};
594
595static struct clk_hw_omap memmap_dummy_ck = {
596 .flags = MEMMAP_ADDRESSING,
597};
598
599static u32 prm_clk_readl(void __iomem *reg)
600{
601 return omap2_clk_readl(&memmap_dummy_ck, reg);
602}
603
604static void prm_clk_writel(u32 val, void __iomem *reg)
605{
606 omap2_clk_writel(val, &memmap_dummy_ck, reg);
607}
608
609static struct ti_clk_ll_ops omap_clk_ll_ops = {
610 .clk_readl = prm_clk_readl,
611 .clk_writel = prm_clk_writel,
612};
613
614int __init of_prcm_init(void)
615{
616 struct device_node *np;
617 void __iomem *mem;
618 int memmap_index = 0;
619
620 ti_clk_ll_ops = &omap_clk_ll_ops;
621
622 for_each_matching_node(np, omap_prcm_dt_match_table) {
623 mem = of_iomap(np, 0);
624 clk_memmaps[memmap_index] = mem;
625 ti_dt_clk_init_provider(np, memmap_index);
626 memmap_index++;
627 }
628
Tero Kristo943a63a2013-10-25 15:28:11 +0300629 return 0;
630}
Tero Kristob550e472014-03-31 18:15:45 +0300631
Tero Kristo3dbb0482014-12-16 18:20:54 +0200632void __init omap3_prcm_legacy_iomaps_init(void)
633{
634 ti_clk_ll_ops = &omap_clk_ll_ops;
635
636 clk_memmaps[TI_CLKM_CM] = cm_base + OMAP3430_IVA2_MOD;
637 clk_memmaps[TI_CLKM_PRM] = prm_base + OMAP3430_IVA2_MOD;
638 clk_memmaps[TI_CLKM_SCRM] = omap_ctrl_base_get();
639}
640
Tero Kristob550e472014-03-31 18:15:45 +0300641static int __init prm_late_init(void)
642{
643 if (prm_ll_data->late_init)
644 return prm_ll_data->late_init();
645 return 0;
646}
647subsys_initcall(prm_late_init);