blob: 058a37e6d11c34955ab37f4df9833cdb0166fb6c [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 Kristoab7b2ff2014-11-20 15:02:59 +020035#include "prm33xx.h"
Tero Kristo0a84a912011-12-16 14:36:58 -070036#include "prm44xx.h"
Tero Kristo48e0c112014-09-08 11:29:43 +030037#include "prm54xx.h"
38#include "prm7xx.h"
39#include "prcm43xx.h"
Paul Walmsleyd9a16f92012-10-29 20:57:39 -060040#include "common.h"
Tero Kristo943a63a2013-10-25 15:28:11 +030041#include "clock.h"
Tero Kristo3dbb0482014-12-16 18:20:54 +020042#include "cm.h"
43#include "control.h"
Tero Kristo0a84a912011-12-16 14:36:58 -070044
45/*
46 * OMAP_PRCM_MAX_NR_PENDING_REG: maximum number of PRM_IRQ*_MPU regs
47 * XXX this is technically not needed, since
48 * omap_prcm_register_chain_handler() could allocate this based on the
49 * actual amount of memory needed for the SoC
50 */
51#define OMAP_PRCM_MAX_NR_PENDING_REG 2
52
53/*
54 * prcm_irq_chips: an array of all of the "generic IRQ chips" in use
55 * by the PRCM interrupt handler code. There will be one 'chip' per
56 * PRM_{IRQSTATUS,IRQENABLE}_MPU register pair. (So OMAP3 will have
57 * one "chip" and OMAP4 will have two.)
58 */
59static struct irq_chip_generic **prcm_irq_chips;
60
61/*
62 * prcm_irq_setup: the PRCM IRQ parameters for the hardware the code
63 * is currently running on. Defined and passed by initialization code
64 * that calls omap_prcm_register_chain_handler().
65 */
66static struct omap_prcm_irq_setup *prcm_irq_setup;
67
Paul Walmsleyd9a16f92012-10-29 20:57:39 -060068/* prm_base: base virtual address of the PRM IP block */
Tero Kristo90129332017-05-31 18:00:00 +030069struct omap_domain_base prm_base;
Paul Walmsleyd9a16f92012-10-29 20:57:39 -060070
Tero Kristo2541d152014-03-31 18:15:44 +030071u16 prm_features;
72
Paul Walmsleye24c3572012-10-21 01:01:11 -060073/*
74 * prm_ll_data: function pointers to SoC-specific implementations of
75 * common PRM functions
76 */
77static struct prm_ll_data null_prm_ll_data;
78static struct prm_ll_data *prm_ll_data = &null_prm_ll_data;
79
Tero Kristo0a84a912011-12-16 14:36:58 -070080/* Private functions */
81
82/*
83 * Move priority events from events to priority_events array
84 */
85static void omap_prcm_events_filter_priority(unsigned long *events,
86 unsigned long *priority_events)
87{
88 int i;
89
90 for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
91 priority_events[i] =
92 events[i] & prcm_irq_setup->priority_mask[i];
93 events[i] ^= priority_events[i];
94 }
95}
96
97/*
98 * PRCM Interrupt Handler
99 *
100 * This is a common handler for the OMAP PRCM interrupts. Pending
101 * interrupts are detected by a call to prcm_pending_events and
102 * dispatched accordingly. Clearing of the wakeup events should be
103 * done by the SoC specific individual handlers.
104 */
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200105static void omap_prcm_irq_handler(struct irq_desc *desc)
Tero Kristo0a84a912011-12-16 14:36:58 -0700106{
107 unsigned long pending[OMAP_PRCM_MAX_NR_PENDING_REG];
108 unsigned long priority_pending[OMAP_PRCM_MAX_NR_PENDING_REG];
109 struct irq_chip *chip = irq_desc_get_chip(desc);
110 unsigned int virtirq;
Venkatraman Sb56f2cb2012-06-25 15:56:39 +0530111 int nr_irq = prcm_irq_setup->nr_regs * 32;
Tero Kristo0a84a912011-12-16 14:36:58 -0700112
113 /*
Tero Kristo91285b62011-12-16 14:36:58 -0700114 * If we are suspended, mask all interrupts from PRCM level,
115 * this does not ack them, and they will be pending until we
116 * re-enable the interrupts, at which point the
117 * omap_prcm_irq_handler will be executed again. The
118 * _save_and_clear_irqen() function must ensure that the PRM
119 * write to disable all IRQs has reached the PRM before
120 * returning, or spurious PRCM interrupts may occur during
121 * suspend.
122 */
123 if (prcm_irq_setup->suspended) {
124 prcm_irq_setup->save_and_clear_irqen(prcm_irq_setup->saved_mask);
125 prcm_irq_setup->suspend_save_flag = true;
126 }
127
128 /*
Tero Kristo0a84a912011-12-16 14:36:58 -0700129 * Loop until all pending irqs are handled, since
130 * generic_handle_irq() can cause new irqs to come
131 */
Tero Kristo91285b62011-12-16 14:36:58 -0700132 while (!prcm_irq_setup->suspended) {
Tero Kristo0a84a912011-12-16 14:36:58 -0700133 prcm_irq_setup->read_pending_irqs(pending);
134
135 /* No bit set, then all IRQs are handled */
Venkatraman Sb56f2cb2012-06-25 15:56:39 +0530136 if (find_first_bit(pending, nr_irq) >= nr_irq)
Tero Kristo0a84a912011-12-16 14:36:58 -0700137 break;
138
139 omap_prcm_events_filter_priority(pending, priority_pending);
140
141 /*
142 * Loop on all currently pending irqs so that new irqs
143 * cannot starve previously pending irqs
144 */
145
146 /* Serve priority events first */
Venkatraman Sb56f2cb2012-06-25 15:56:39 +0530147 for_each_set_bit(virtirq, priority_pending, nr_irq)
Tero Kristo0a84a912011-12-16 14:36:58 -0700148 generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
149
150 /* Serve normal events next */
Venkatraman Sb56f2cb2012-06-25 15:56:39 +0530151 for_each_set_bit(virtirq, pending, nr_irq)
Tero Kristo0a84a912011-12-16 14:36:58 -0700152 generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
153 }
154 if (chip->irq_ack)
155 chip->irq_ack(&desc->irq_data);
156 if (chip->irq_eoi)
157 chip->irq_eoi(&desc->irq_data);
158 chip->irq_unmask(&desc->irq_data);
159
160 prcm_irq_setup->ocp_barrier(); /* avoid spurious IRQs */
161}
162
163/* Public functions */
164
165/**
166 * omap_prcm_event_to_irq - given a PRCM event name, returns the
167 * corresponding IRQ on which the handler should be registered
168 * @name: name of the PRCM interrupt bit to look up - see struct omap_prcm_irq
169 *
170 * Returns the Linux internal IRQ ID corresponding to @name upon success,
171 * or -ENOENT upon failure.
172 */
173int omap_prcm_event_to_irq(const char *name)
174{
175 int i;
176
177 if (!prcm_irq_setup || !name)
178 return -ENOENT;
179
180 for (i = 0; i < prcm_irq_setup->nr_irqs; i++)
181 if (!strcmp(prcm_irq_setup->irqs[i].name, name))
182 return prcm_irq_setup->base_irq +
183 prcm_irq_setup->irqs[i].offset;
184
185 return -ENOENT;
186}
187
188/**
189 * omap_prcm_irq_cleanup - reverses memory allocated and other steps
190 * done by omap_prcm_register_chain_handler()
191 *
192 * No return value.
193 */
194void omap_prcm_irq_cleanup(void)
195{
Marc Zyngier0fb22a82015-01-17 10:21:08 +0000196 unsigned int irq;
Tero Kristo0a84a912011-12-16 14:36:58 -0700197 int i;
198
199 if (!prcm_irq_setup) {
200 pr_err("PRCM: IRQ handler not initialized; cannot cleanup\n");
201 return;
202 }
203
204 if (prcm_irq_chips) {
205 for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
206 if (prcm_irq_chips[i])
207 irq_remove_generic_chip(prcm_irq_chips[i],
208 0xffffffff, 0, 0);
209 prcm_irq_chips[i] = NULL;
210 }
211 kfree(prcm_irq_chips);
212 prcm_irq_chips = NULL;
213 }
214
Tero Kristo91285b62011-12-16 14:36:58 -0700215 kfree(prcm_irq_setup->saved_mask);
216 prcm_irq_setup->saved_mask = NULL;
217
Tero Kristo0a84a912011-12-16 14:36:58 -0700218 kfree(prcm_irq_setup->priority_mask);
219 prcm_irq_setup->priority_mask = NULL;
220
Tony Lindgren3da52162017-10-10 14:27:13 -0700221 irq = prcm_irq_setup->irq;
Marc Zyngier0fb22a82015-01-17 10:21:08 +0000222 irq_set_chained_handler(irq, NULL);
Tero Kristo0a84a912011-12-16 14:36:58 -0700223
224 if (prcm_irq_setup->base_irq > 0)
225 irq_free_descs(prcm_irq_setup->base_irq,
226 prcm_irq_setup->nr_regs * 32);
227 prcm_irq_setup->base_irq = 0;
228}
229
Tero Kristo91285b62011-12-16 14:36:58 -0700230void omap_prcm_irq_prepare(void)
231{
232 prcm_irq_setup->suspended = true;
233}
234
235void omap_prcm_irq_complete(void)
236{
237 prcm_irq_setup->suspended = false;
238
239 /* If we have not saved the masks, do not attempt to restore */
240 if (!prcm_irq_setup->suspend_save_flag)
241 return;
242
243 prcm_irq_setup->suspend_save_flag = false;
244
245 /*
246 * Re-enable all masked PRCM irq sources, this causes the PRCM
247 * interrupt to fire immediately if the events were masked
248 * previously in the chain handler
249 */
250 prcm_irq_setup->restore_irqen(prcm_irq_setup->saved_mask);
251}
252
Tero Kristo0a84a912011-12-16 14:36:58 -0700253/**
254 * omap_prcm_register_chain_handler - initializes the prcm chained interrupt
255 * handler based on provided parameters
256 * @irq_setup: hardware data about the underlying PRM/PRCM
257 *
258 * Set up the PRCM chained interrupt handler on the PRCM IRQ. Sets up
259 * one generic IRQ chip per PRM interrupt status/enable register pair.
260 * Returns 0 upon success, -EINVAL if called twice or if invalid
261 * arguments are passed, or -ENOMEM on any other error.
262 */
263int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup)
264{
Paul Walmsleyeeb37112012-04-13 06:34:32 -0600265 int nr_regs;
Tero Kristo0a84a912011-12-16 14:36:58 -0700266 u32 mask[OMAP_PRCM_MAX_NR_PENDING_REG];
Tony Lindgren2a26d312017-05-31 15:51:36 -0700267 int offset, i, irq;
Tero Kristo0a84a912011-12-16 14:36:58 -0700268 struct irq_chip_generic *gc;
269 struct irq_chip_type *ct;
270
271 if (!irq_setup)
272 return -EINVAL;
273
Paul Walmsleyeeb37112012-04-13 06:34:32 -0600274 nr_regs = irq_setup->nr_regs;
275
Tero Kristo0a84a912011-12-16 14:36:58 -0700276 if (prcm_irq_setup) {
277 pr_err("PRCM: already initialized; won't reinitialize\n");
278 return -EINVAL;
279 }
280
281 if (nr_regs > OMAP_PRCM_MAX_NR_PENDING_REG) {
282 pr_err("PRCM: nr_regs too large\n");
283 return -EINVAL;
284 }
285
286 prcm_irq_setup = irq_setup;
287
Kees Cook6396bb22018-06-12 14:03:40 -0700288 prcm_irq_chips = kcalloc(nr_regs, sizeof(void *), GFP_KERNEL);
289 prcm_irq_setup->saved_mask = kcalloc(nr_regs, sizeof(u32),
290 GFP_KERNEL);
291 prcm_irq_setup->priority_mask = kcalloc(nr_regs, sizeof(u32),
292 GFP_KERNEL);
Tero Kristo0a84a912011-12-16 14:36:58 -0700293
Tero Kristo91285b62011-12-16 14:36:58 -0700294 if (!prcm_irq_chips || !prcm_irq_setup->saved_mask ||
Markus Elfring9a6b6f72016-12-03 21:46:02 +0100295 !prcm_irq_setup->priority_mask)
Tero Kristo0a84a912011-12-16 14:36:58 -0700296 goto err;
Tero Kristo0a84a912011-12-16 14:36:58 -0700297
298 memset(mask, 0, sizeof(mask));
299
300 for (i = 0; i < irq_setup->nr_irqs; i++) {
301 offset = irq_setup->irqs[i].offset;
302 mask[offset >> 5] |= 1 << (offset & 0x1f);
303 if (irq_setup->irqs[i].priority)
304 irq_setup->priority_mask[offset >> 5] |=
305 1 << (offset & 0x1f);
306 }
307
Tony Lindgren3da52162017-10-10 14:27:13 -0700308 irq = irq_setup->irq;
Marc Zyngier0fb22a82015-01-17 10:21:08 +0000309 irq_set_chained_handler(irq, omap_prcm_irq_handler);
Tero Kristo0a84a912011-12-16 14:36:58 -0700310
311 irq_setup->base_irq = irq_alloc_descs(-1, 0, irq_setup->nr_regs * 32,
312 0);
313
314 if (irq_setup->base_irq < 0) {
315 pr_err("PRCM: failed to allocate irq descs: %d\n",
316 irq_setup->base_irq);
317 goto err;
318 }
319
Ming Lei4ba7c3c2012-03-22 09:23:37 +0800320 for (i = 0; i < irq_setup->nr_regs; i++) {
Tero Kristo0a84a912011-12-16 14:36:58 -0700321 gc = irq_alloc_generic_chip("PRCM", 1,
Tero Kristo90129332017-05-31 18:00:00 +0300322 irq_setup->base_irq + i * 32, prm_base.va,
Tero Kristo0a84a912011-12-16 14:36:58 -0700323 handle_level_irq);
324
325 if (!gc) {
326 pr_err("PRCM: failed to allocate generic chip\n");
327 goto err;
328 }
329 ct = gc->chip_types;
330 ct->chip.irq_ack = irq_gc_ack_set_bit;
331 ct->chip.irq_mask = irq_gc_mask_clr_bit;
332 ct->chip.irq_unmask = irq_gc_mask_set_bit;
333
334 ct->regs.ack = irq_setup->ack + i * 4;
335 ct->regs.mask = irq_setup->mask + i * 4;
336
337 irq_setup_generic_chip(gc, mask[i], 0, IRQ_NOREQUEST, 0);
338 prcm_irq_chips[i] = gc;
339 }
340
Tony Lindgren2a26d312017-05-31 15:51:36 -0700341 irq = omap_prcm_event_to_irq("io");
342 omap_pcs_legacy_init(irq, irq_setup->reconfigure_io_chain);
Tony Lindgren30a69ef2013-10-10 15:45:13 -0700343
Tero Kristo0a84a912011-12-16 14:36:58 -0700344 return 0;
345
346err:
347 omap_prcm_irq_cleanup();
348 return -ENOMEM;
349}
R Sricharan3f4990f2012-07-04 05:04:00 -0600350
Paul Walmsleye24c3572012-10-21 01:01:11 -0600351/**
Paul Walmsleyd9a16f92012-10-29 20:57:39 -0600352 * omap2_set_globals_prm - set the PRM base address (for early use)
353 * @prm: PRM base virtual address
354 *
355 * XXX Will be replaced when the PRM/CM drivers are completed.
R Sricharan3f4990f2012-07-04 05:04:00 -0600356 */
Paul Walmsleyd9a16f92012-10-29 20:57:39 -0600357void __init omap2_set_globals_prm(void __iomem *prm)
R Sricharan3f4990f2012-07-04 05:04:00 -0600358{
Tero Kristo90129332017-05-31 18:00:00 +0300359 prm_base.va = prm;
Paul Walmsleyd9a16f92012-10-29 20:57:39 -0600360}
361
362/**
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600363 * prm_read_reset_sources - return the sources of the SoC's last reset
364 *
365 * Return a u32 bitmask representing the reset sources that caused the
366 * SoC to reset. The low-level per-SoC functions called by this
367 * function remap the SoC-specific reset source bits into an
368 * OMAP-common set of reset source bits, defined in
369 * arch/arm/mach-omap2/prm.h. Returns the standardized reset source
370 * u32 bitmask from the hardware upon success, or returns (1 <<
371 * OMAP_UNKNOWN_RST_SRC_ID_SHIFT) if no low-level read_reset_sources()
372 * function was registered.
R Sricharan3f4990f2012-07-04 05:04:00 -0600373 */
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600374u32 prm_read_reset_sources(void)
R Sricharan3f4990f2012-07-04 05:04:00 -0600375{
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600376 u32 ret = 1 << OMAP_UNKNOWN_RST_SRC_ID_SHIFT;
377
378 if (prm_ll_data->read_reset_sources)
379 ret = prm_ll_data->read_reset_sources();
380 else
381 WARN_ONCE(1, "prm: %s: no mapping function defined for reset sources\n", __func__);
382
383 return ret;
384}
385
386/**
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -0700387 * prm_was_any_context_lost_old - was device context lost? (old API)
388 * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
389 * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
390 * @idx: CONTEXT register offset
391 *
392 * Return 1 if any bits were set in the *_CONTEXT_* register
393 * identified by (@part, @inst, @idx), which means that some context
394 * was lost for that module; otherwise, return 0. XXX Deprecated;
395 * callers need to use a less-SoC-dependent way to identify hardware
396 * IP blocks.
397 */
398bool prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
399{
400 bool ret = true;
401
402 if (prm_ll_data->was_any_context_lost_old)
403 ret = prm_ll_data->was_any_context_lost_old(part, inst, idx);
404 else
405 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
406 __func__);
407
408 return ret;
409}
410
411/**
412 * prm_clear_context_lost_flags_old - clear context loss flags (old API)
413 * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
414 * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
415 * @idx: CONTEXT register offset
416 *
417 * Clear hardware context loss bits for the module identified by
418 * (@part, @inst, @idx). No return value. XXX Deprecated; callers
419 * need to use a less-SoC-dependent way to identify hardware IP
420 * blocks.
421 */
422void prm_clear_context_loss_flags_old(u8 part, s16 inst, u16 idx)
423{
424 if (prm_ll_data->clear_context_loss_flags_old)
425 prm_ll_data->clear_context_loss_flags_old(part, inst, idx);
426 else
427 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
428 __func__);
429}
430
431/**
Tero Kristoefd44dc2014-10-27 08:39:24 -0700432 * omap_prm_assert_hardreset - assert hardreset for an IP block
433 * @shift: register bit shift corresponding to the reset line
434 * @part: PRM partition
435 * @prm_mod: PRM submodule base or instance offset
436 * @offset: register offset
437 *
438 * Asserts a hardware reset line for an IP block.
439 */
440int omap_prm_assert_hardreset(u8 shift, u8 part, s16 prm_mod, u16 offset)
441{
442 if (!prm_ll_data->assert_hardreset) {
443 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
444 __func__);
445 return -EINVAL;
446 }
447
448 return prm_ll_data->assert_hardreset(shift, part, prm_mod, offset);
449}
450
451/**
Tero Kristo37fb59d2014-10-27 08:39:25 -0700452 * omap_prm_deassert_hardreset - deassert hardreset for an IP block
453 * @shift: register bit shift corresponding to the reset line
454 * @st_shift: reset status bit shift corresponding to the reset line
455 * @part: PRM partition
456 * @prm_mod: PRM submodule base or instance offset
457 * @offset: register offset
458 * @st_offset: status register offset
459 *
460 * Deasserts a hardware reset line for an IP block.
461 */
462int omap_prm_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 prm_mod,
463 u16 offset, u16 st_offset)
464{
465 if (!prm_ll_data->deassert_hardreset) {
466 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
467 __func__);
468 return -EINVAL;
469 }
470
471 return prm_ll_data->deassert_hardreset(shift, st_shift, part, prm_mod,
472 offset, st_offset);
473}
474
475/**
Tero Kristo1bc28b32014-10-27 08:39:25 -0700476 * omap_prm_is_hardreset_asserted - check the hardreset status for an IP block
477 * @shift: register bit shift corresponding to the reset line
478 * @part: PRM partition
479 * @prm_mod: PRM submodule base or instance offset
480 * @offset: register offset
481 *
482 * Checks if a hardware reset line for an IP block is enabled or not.
483 */
484int omap_prm_is_hardreset_asserted(u8 shift, u8 part, s16 prm_mod, u16 offset)
485{
486 if (!prm_ll_data->is_hardreset_asserted) {
487 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
488 __func__);
489 return -EINVAL;
490 }
491
492 return prm_ll_data->is_hardreset_asserted(shift, part, prm_mod, offset);
493}
494
495/**
Tero Kristo4984eea2014-10-27 08:39:26 -0700496 * omap_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
497 *
498 * Clear any previously-latched I/O wakeup events and ensure that the
499 * I/O wakeup gates are aligned with the current mux settings.
500 * Calls SoC specific I/O chain reconfigure function if available,
501 * otherwise does nothing.
502 */
503void omap_prm_reconfigure_io_chain(void)
504{
505 if (!prcm_irq_setup || !prcm_irq_setup->reconfigure_io_chain)
506 return;
507
508 prcm_irq_setup->reconfigure_io_chain();
509}
510
511/**
Tero Kristo61c86212014-10-27 08:39:26 -0700512 * omap_prm_reset_system - trigger global SW reset
513 *
514 * Triggers SoC specific global warm reset to reboot the device.
515 */
516void omap_prm_reset_system(void)
517{
518 if (!prm_ll_data->reset_system) {
519 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
520 __func__);
521 return;
522 }
523
524 prm_ll_data->reset_system();
525
526 while (1)
527 cpu_relax();
528}
529
530/**
Tero Kristo9cb6d362014-04-04 12:31:51 +0300531 * omap_prm_clear_mod_irqs - clear wake-up events from PRCM interrupt
532 * @module: PRM module to clear wakeups from
533 * @regs: register to clear
534 * @wkst_mask: wkst bits to clear
535 *
536 * Clears any wakeup events for the module and register set defined.
537 * Uses SoC specific implementation to do the actual wakeup status
538 * clearing.
539 */
540int omap_prm_clear_mod_irqs(s16 module, u8 regs, u32 wkst_mask)
541{
542 if (!prm_ll_data->clear_mod_irqs) {
543 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
544 __func__);
545 return -EINVAL;
546 }
547
548 return prm_ll_data->clear_mod_irqs(module, regs, wkst_mask);
549}
550
551/**
Tero Kristoe9f1ddc2014-04-04 15:52:01 +0300552 * omap_prm_vp_check_txdone - check voltage processor TX done status
553 *
554 * Checks if voltage processor transmission has been completed.
555 * Returns non-zero if a transmission has completed, 0 otherwise.
556 */
557u32 omap_prm_vp_check_txdone(u8 vp_id)
558{
559 if (!prm_ll_data->vp_check_txdone) {
560 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
561 __func__);
562 return 0;
563 }
564
565 return prm_ll_data->vp_check_txdone(vp_id);
566}
567
568/**
569 * omap_prm_vp_clear_txdone - clears voltage processor TX done status
570 *
571 * Clears the status bit for completed voltage processor transmission
572 * returned by prm_vp_check_txdone.
573 */
574void omap_prm_vp_clear_txdone(u8 vp_id)
575{
576 if (!prm_ll_data->vp_clear_txdone) {
577 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
578 __func__);
579 return;
580 }
581
582 prm_ll_data->vp_clear_txdone(vp_id);
583}
584
585/**
Paul Walmsleye24c3572012-10-21 01:01:11 -0600586 * prm_register - register per-SoC low-level data with the PRM
587 * @pld: low-level per-SoC OMAP PRM data & function pointers to register
588 *
589 * Register per-SoC low-level OMAP PRM data and function pointers with
590 * the OMAP PRM common interface. The caller must keep the data
591 * pointed to by @pld valid until it calls prm_unregister() and
592 * it returns successfully. Returns 0 upon success, -EINVAL if @pld
593 * is NULL, or -EEXIST if prm_register() has already been called
594 * without an intervening prm_unregister().
595 */
596int prm_register(struct prm_ll_data *pld)
597{
598 if (!pld)
599 return -EINVAL;
600
601 if (prm_ll_data != &null_prm_ll_data)
602 return -EEXIST;
603
604 prm_ll_data = pld;
605
R Sricharan3f4990f2012-07-04 05:04:00 -0600606 return 0;
607}
608
Paul Walmsleye24c3572012-10-21 01:01:11 -0600609/**
610 * prm_unregister - unregister per-SoC low-level data & function pointers
611 * @pld: low-level per-SoC OMAP PRM data & function pointers to unregister
612 *
613 * Unregister per-SoC low-level OMAP PRM data and function pointers
614 * that were previously registered with prm_register(). The
615 * caller may not destroy any of the data pointed to by @pld until
616 * this function returns successfully. Returns 0 upon success, or
617 * -EINVAL if @pld is NULL or if @pld does not match the struct
618 * prm_ll_data * previously registered by prm_register().
619 */
620int prm_unregister(struct prm_ll_data *pld)
R Sricharan3f4990f2012-07-04 05:04:00 -0600621{
Paul Walmsleye24c3572012-10-21 01:01:11 -0600622 if (!pld || prm_ll_data != pld)
623 return -EINVAL;
R Sricharan3f4990f2012-07-04 05:04:00 -0600624
Paul Walmsleye24c3572012-10-21 01:01:11 -0600625 prm_ll_data = &null_prm_ll_data;
626
R Sricharan3f4990f2012-07-04 05:04:00 -0600627 return 0;
628}
Tero Kristo943a63a2013-10-25 15:28:11 +0300629
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200630#ifdef CONFIG_ARCH_OMAP2
631static struct omap_prcm_init_data omap2_prm_data __initdata = {
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200632 .index = TI_CLKM_PRM,
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200633 .init = omap2xxx_prm_init,
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200634};
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200635#endif
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200636
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200637#ifdef CONFIG_ARCH_OMAP3
638static struct omap_prcm_init_data omap3_prm_data __initdata = {
Tero Kristoae521d4d2014-11-11 17:17:18 +0200639 .index = TI_CLKM_PRM,
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200640 .init = omap3xxx_prm_init,
Tero Kristoae521d4d2014-11-11 17:17:18 +0200641
642 /*
643 * IVA2 offset is a negative value, must offset the prm_base
644 * address by this to get it to positive
645 */
646 .offset = -OMAP3430_IVA2_MOD,
647};
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200648#endif
Tero Kristoae521d4d2014-11-11 17:17:18 +0200649
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200650#if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_TI81XX)
651static struct omap_prcm_init_data am3_prm_data __initdata = {
652 .index = TI_CLKM_PRM,
653 .init = am33xx_prm_init,
654};
Tony Lindgrendbb7e702015-12-21 10:06:52 -0800655#endif
Tony Lindgren4e34df0c2015-12-03 12:02:31 -0800656
Tony Lindgrendbb7e702015-12-21 10:06:52 -0800657#ifdef CONFIG_SOC_TI81XX
Tony Lindgren4e34df0c2015-12-03 12:02:31 -0800658static struct omap_prcm_init_data dm814_pllss_data __initdata = {
659 .index = TI_CLKM_PLLSS,
660 .init = am33xx_prm_init,
661};
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200662#endif
663
Tero Kristo48e0c112014-09-08 11:29:43 +0300664#ifdef CONFIG_ARCH_OMAP4
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200665static struct omap_prcm_init_data omap4_prm_data __initdata = {
666 .index = TI_CLKM_PRM,
667 .init = omap44xx_prm_init,
Tero Kristo48e0c112014-09-08 11:29:43 +0300668 .device_inst_offset = OMAP4430_PRM_DEVICE_INST,
Tony Lindgren3da52162017-10-10 14:27:13 -0700669 .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
Tero Kristo48e0c112014-09-08 11:29:43 +0300670};
671#endif
672
673#ifdef CONFIG_SOC_OMAP5
674static struct omap_prcm_init_data omap5_prm_data __initdata = {
675 .index = TI_CLKM_PRM,
676 .init = omap44xx_prm_init,
677 .device_inst_offset = OMAP54XX_PRM_DEVICE_INST,
Tero Kristo8b5b9a22014-11-21 14:45:29 +0200678 .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
Tero Kristo48e0c112014-09-08 11:29:43 +0300679};
680#endif
681
682#ifdef CONFIG_SOC_DRA7XX
683static struct omap_prcm_init_data dra7_prm_data __initdata = {
684 .index = TI_CLKM_PRM,
685 .init = omap44xx_prm_init,
686 .device_inst_offset = DRA7XX_PRM_DEVICE_INST,
Tero Kristo8b5b9a22014-11-21 14:45:29 +0200687 .flags = PRM_HAS_IO_WAKEUP,
Tero Kristo48e0c112014-09-08 11:29:43 +0300688};
689#endif
690
691#ifdef CONFIG_SOC_AM43XX
692static struct omap_prcm_init_data am4_prm_data __initdata = {
693 .index = TI_CLKM_PRM,
694 .init = omap44xx_prm_init,
695 .device_inst_offset = AM43XX_PRM_DEVICE_INST,
Keerthy8740a142015-07-16 17:23:19 +0530696 .flags = PRM_HAS_IO_WAKEUP,
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200697};
698#endif
699
700#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
701static struct omap_prcm_init_data scrm_data __initdata = {
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200702 .index = TI_CLKM_SCRM,
703};
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200704#endif
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200705
Arnd Bergmann05278732017-05-11 13:50:16 +0200706static const struct of_device_id omap_prcm_dt_match_table[] __initconst = {
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200707#ifdef CONFIG_SOC_AM33XX
708 { .compatible = "ti,am3-prcm", .data = &am3_prm_data },
709#endif
710#ifdef CONFIG_SOC_AM43XX
Tero Kristo48e0c112014-09-08 11:29:43 +0300711 { .compatible = "ti,am4-prcm", .data = &am4_prm_data },
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200712#endif
713#ifdef CONFIG_SOC_TI81XX
714 { .compatible = "ti,dm814-prcm", .data = &am3_prm_data },
Tony Lindgren4e34df0c2015-12-03 12:02:31 -0800715 { .compatible = "ti,dm814-pllss", .data = &dm814_pllss_data },
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200716 { .compatible = "ti,dm816-prcm", .data = &am3_prm_data },
717#endif
718#ifdef CONFIG_ARCH_OMAP2
719 { .compatible = "ti,omap2-prcm", .data = &omap2_prm_data },
720#endif
721#ifdef CONFIG_ARCH_OMAP3
Tero Kristoae521d4d2014-11-11 17:17:18 +0200722 { .compatible = "ti,omap3-prm", .data = &omap3_prm_data },
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200723#endif
724#ifdef CONFIG_ARCH_OMAP4
725 { .compatible = "ti,omap4-prm", .data = &omap4_prm_data },
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200726 { .compatible = "ti,omap4-scrm", .data = &scrm_data },
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200727#endif
728#ifdef CONFIG_SOC_OMAP5
Tero Kristo48e0c112014-09-08 11:29:43 +0300729 { .compatible = "ti,omap5-prm", .data = &omap5_prm_data },
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200730 { .compatible = "ti,omap5-scrm", .data = &scrm_data },
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200731#endif
732#ifdef CONFIG_SOC_DRA7XX
Tero Kristo48e0c112014-09-08 11:29:43 +0300733 { .compatible = "ti,dra7-prm", .data = &dra7_prm_data },
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200734#endif
Tero Kristo943a63a2013-10-25 15:28:11 +0300735 { }
736};
737
Tero Kristo3a1a3882014-11-18 14:59:36 +0200738/**
Tero Kristoae521d4d2014-11-11 17:17:18 +0200739 * omap2_prm_base_init - initialize iomappings for the PRM driver
740 *
741 * Detects and initializes the iomappings for the PRM driver, based
742 * on the DT data. Returns 0 in success, negative error value
743 * otherwise.
744 */
745int __init omap2_prm_base_init(void)
746{
747 struct device_node *np;
748 const struct of_device_id *match;
749 struct omap_prcm_init_data *data;
Tero Kristo90129332017-05-31 18:00:00 +0300750 struct resource res;
751 int ret;
Tero Kristoae521d4d2014-11-11 17:17:18 +0200752
753 for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
754 data = (struct omap_prcm_init_data *)match->data;
755
Tero Kristo90129332017-05-31 18:00:00 +0300756 ret = of_address_to_resource(np, 0, &res);
757 if (ret)
758 return ret;
Tero Kristoae521d4d2014-11-11 17:17:18 +0200759
Tero Kristo90129332017-05-31 18:00:00 +0300760 data->mem = ioremap(res.start, resource_size(&res));
Tero Kristoae521d4d2014-11-11 17:17:18 +0200761
Tero Kristo90129332017-05-31 18:00:00 +0300762 if (data->index == TI_CLKM_PRM) {
763 prm_base.va = data->mem + data->offset;
764 prm_base.pa = res.start + data->offset;
765 }
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200766
767 data->np = np;
768
769 if (data->init)
770 data->init(data);
Tero Kristoae521d4d2014-11-11 17:17:18 +0200771 }
772
773 return 0;
774}
775
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200776int __init omap2_prcm_base_init(void)
777{
Tero Kristo425dc8b2014-11-21 15:51:37 +0200778 int ret;
779
780 ret = omap2_prm_base_init();
781 if (ret)
782 return ret;
783
784 return omap2_cm_base_init();
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200785}
786
Tero Kristoae521d4d2014-11-11 17:17:18 +0200787/**
Tero Kristo3a1a3882014-11-18 14:59:36 +0200788 * omap_prcm_init - low level init for the PRCM drivers
789 *
790 * Initializes the low level clock infrastructure for PRCM drivers.
791 * Returns 0 in success, negative error value in failure.
792 */
793int __init omap_prcm_init(void)
Tero Kristo943a63a2013-10-25 15:28:11 +0300794{
795 struct device_node *np;
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200796 const struct of_device_id *match;
797 const struct omap_prcm_init_data *data;
Tero Kristo9f029b12014-10-22 15:15:36 +0300798 int ret;
Tero Kristo943a63a2013-10-25 15:28:11 +0300799
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200800 for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
801 data = match->data;
802
Tero Kristo80cbb222015-02-06 16:00:32 +0200803 ret = omap2_clk_provider_init(np, data->index, NULL, data->mem);
Tero Kristo9f029b12014-10-22 15:15:36 +0300804 if (ret)
805 return ret;
Tero Kristo943a63a2013-10-25 15:28:11 +0300806 }
807
Tero Kristofe874142014-03-12 18:33:45 +0200808 omap_cm_init();
809
Tero Kristo943a63a2013-10-25 15:28:11 +0300810 return 0;
811}
Tero Kristob550e472014-03-31 18:15:45 +0300812
813static int __init prm_late_init(void)
814{
815 if (prm_ll_data->late_init)
816 return prm_ll_data->late_init();
817 return 0;
818}
819subsys_initcall(prm_late_init);