2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2011-12-16 21:36:58 +00:00
|
|
|
/*
|
|
|
|
* OMAP2+ common Power & Reset Management (PRM) IP block functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Texas Instruments, Inc.
|
|
|
|
* Tero Kristo <t-kristo@ti.com>
|
|
|
|
*
|
|
|
|
* For historical purposes, the API used to configure the PRM
|
|
|
|
* interrupt handler refers to it as the "PRCM interrupt." The
|
|
|
|
* underlying registers are located in the PRM on OMAP3/4.
|
|
|
|
*
|
|
|
|
* XXX This code should eventually be moved to a PRM driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/slab.h>
|
2013-10-25 12:28:11 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/clk/ti.h>
|
2011-12-16 21:36:58 +00:00
|
|
|
|
2013-10-10 22:45:13 +00:00
|
|
|
#include "soc.h"
|
2011-12-16 21:36:58 +00:00
|
|
|
#include "prm2xxx_3xxx.h"
|
2012-10-21 07:01:13 +00:00
|
|
|
#include "prm2xxx.h"
|
|
|
|
#include "prm3xxx.h"
|
2014-11-20 13:02:59 +00:00
|
|
|
#include "prm33xx.h"
|
2011-12-16 21:36:58 +00:00
|
|
|
#include "prm44xx.h"
|
2014-09-08 08:29:43 +00:00
|
|
|
#include "prm54xx.h"
|
|
|
|
#include "prm7xx.h"
|
|
|
|
#include "prcm43xx.h"
|
2012-10-30 02:57:39 +00:00
|
|
|
#include "common.h"
|
2013-10-25 12:28:11 +00:00
|
|
|
#include "clock.h"
|
2014-12-16 16:20:54 +00:00
|
|
|
#include "cm.h"
|
|
|
|
#include "control.h"
|
2011-12-16 21:36:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* OMAP_PRCM_MAX_NR_PENDING_REG: maximum number of PRM_IRQ*_MPU regs
|
|
|
|
* XXX this is technically not needed, since
|
|
|
|
* omap_prcm_register_chain_handler() could allocate this based on the
|
|
|
|
* actual amount of memory needed for the SoC
|
|
|
|
*/
|
|
|
|
#define OMAP_PRCM_MAX_NR_PENDING_REG 2
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prcm_irq_chips: an array of all of the "generic IRQ chips" in use
|
|
|
|
* by the PRCM interrupt handler code. There will be one 'chip' per
|
|
|
|
* PRM_{IRQSTATUS,IRQENABLE}_MPU register pair. (So OMAP3 will have
|
|
|
|
* one "chip" and OMAP4 will have two.)
|
|
|
|
*/
|
|
|
|
static struct irq_chip_generic **prcm_irq_chips;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prcm_irq_setup: the PRCM IRQ parameters for the hardware the code
|
|
|
|
* is currently running on. Defined and passed by initialization code
|
|
|
|
* that calls omap_prcm_register_chain_handler().
|
|
|
|
*/
|
|
|
|
static struct omap_prcm_irq_setup *prcm_irq_setup;
|
|
|
|
|
2012-10-30 02:57:39 +00:00
|
|
|
/* prm_base: base virtual address of the PRM IP block */
|
2017-05-31 15:00:00 +00:00
|
|
|
struct omap_domain_base prm_base;
|
2012-10-30 02:57:39 +00:00
|
|
|
|
2014-03-31 15:15:44 +00:00
|
|
|
u16 prm_features;
|
|
|
|
|
ARM: OMAP2+: PRM: prepare for use of prm_ll_data function pointers
There are several PRM operations which behave similarly across OMAP2+
SoCs, but which have slight differences in their underlying
implementations. For example, to fetch the SoC's last reset sources,
different registers are read across OMAP2xxx, 3xxx, and 44xx, and
different bits are used on each SoC. But the information returned is
so similar that a single, common interface for drivers is useful.
This patch creates the support code for this function pointer
registration process. No function pointers are included yet, but a
subsequent patch will create one for the reset source API.
To illustrate the end goal with the above reset source example, each
per-SoC driver will use its own low-level implementation function --
e.g., prm2xxx.c would contain omap2xxx_prm_read_reset_sources(). This
function would read the appropriate register and remap the register
bits to a standard set of reset source bits. When the prm2xxx.c
driver is loaded, it would register this function with the common PRM
driver, prm.c. prm.c would then export a common function,
omap_prm_read_reset_sources(). Calling it would call through to the
function pointer for the currently-registered SoC PRM driver. This
will allow other drivers to use PRM-provided data and operations
without needing to know which SoC is currently in use.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
2012-10-21 07:01:11 +00:00
|
|
|
/*
|
|
|
|
* prm_ll_data: function pointers to SoC-specific implementations of
|
|
|
|
* common PRM functions
|
|
|
|
*/
|
|
|
|
static struct prm_ll_data null_prm_ll_data;
|
|
|
|
static struct prm_ll_data *prm_ll_data = &null_prm_ll_data;
|
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
/* Private functions */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move priority events from events to priority_events array
|
|
|
|
*/
|
|
|
|
static void omap_prcm_events_filter_priority(unsigned long *events,
|
|
|
|
unsigned long *priority_events)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
|
|
|
|
priority_events[i] =
|
|
|
|
events[i] & prcm_irq_setup->priority_mask[i];
|
|
|
|
events[i] ^= priority_events[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PRCM Interrupt Handler
|
|
|
|
*
|
|
|
|
* This is a common handler for the OMAP PRCM interrupts. Pending
|
|
|
|
* interrupts are detected by a call to prcm_pending_events and
|
|
|
|
* dispatched accordingly. Clearing of the wakeup events should be
|
|
|
|
* done by the SoC specific individual handlers.
|
|
|
|
*/
|
2015-09-14 08:42:37 +00:00
|
|
|
static void omap_prcm_irq_handler(struct irq_desc *desc)
|
2011-12-16 21:36:58 +00:00
|
|
|
{
|
|
|
|
unsigned long pending[OMAP_PRCM_MAX_NR_PENDING_REG];
|
|
|
|
unsigned long priority_pending[OMAP_PRCM_MAX_NR_PENDING_REG];
|
|
|
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
|
|
|
unsigned int virtirq;
|
2012-06-25 10:26:39 +00:00
|
|
|
int nr_irq = prcm_irq_setup->nr_regs * 32;
|
2011-12-16 21:36:58 +00:00
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
/*
|
|
|
|
* If we are suspended, mask all interrupts from PRCM level,
|
|
|
|
* this does not ack them, and they will be pending until we
|
|
|
|
* re-enable the interrupts, at which point the
|
|
|
|
* omap_prcm_irq_handler will be executed again. The
|
|
|
|
* _save_and_clear_irqen() function must ensure that the PRM
|
|
|
|
* write to disable all IRQs has reached the PRM before
|
|
|
|
* returning, or spurious PRCM interrupts may occur during
|
|
|
|
* suspend.
|
|
|
|
*/
|
|
|
|
if (prcm_irq_setup->suspended) {
|
|
|
|
prcm_irq_setup->save_and_clear_irqen(prcm_irq_setup->saved_mask);
|
|
|
|
prcm_irq_setup->suspend_save_flag = true;
|
|
|
|
}
|
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
/*
|
|
|
|
* Loop until all pending irqs are handled, since
|
|
|
|
* generic_handle_irq() can cause new irqs to come
|
|
|
|
*/
|
2011-12-16 21:36:58 +00:00
|
|
|
while (!prcm_irq_setup->suspended) {
|
2011-12-16 21:36:58 +00:00
|
|
|
prcm_irq_setup->read_pending_irqs(pending);
|
|
|
|
|
|
|
|
/* No bit set, then all IRQs are handled */
|
2012-06-25 10:26:39 +00:00
|
|
|
if (find_first_bit(pending, nr_irq) >= nr_irq)
|
2011-12-16 21:36:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
omap_prcm_events_filter_priority(pending, priority_pending);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop on all currently pending irqs so that new irqs
|
|
|
|
* cannot starve previously pending irqs
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Serve priority events first */
|
2012-06-25 10:26:39 +00:00
|
|
|
for_each_set_bit(virtirq, priority_pending, nr_irq)
|
2011-12-16 21:36:58 +00:00
|
|
|
generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
|
|
|
|
|
|
|
|
/* Serve normal events next */
|
2012-06-25 10:26:39 +00:00
|
|
|
for_each_set_bit(virtirq, pending, nr_irq)
|
2011-12-16 21:36:58 +00:00
|
|
|
generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
|
|
|
|
}
|
|
|
|
if (chip->irq_ack)
|
|
|
|
chip->irq_ack(&desc->irq_data);
|
|
|
|
if (chip->irq_eoi)
|
|
|
|
chip->irq_eoi(&desc->irq_data);
|
|
|
|
chip->irq_unmask(&desc->irq_data);
|
|
|
|
|
|
|
|
prcm_irq_setup->ocp_barrier(); /* avoid spurious IRQs */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Public functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_prcm_event_to_irq - given a PRCM event name, returns the
|
|
|
|
* corresponding IRQ on which the handler should be registered
|
|
|
|
* @name: name of the PRCM interrupt bit to look up - see struct omap_prcm_irq
|
|
|
|
*
|
|
|
|
* Returns the Linux internal IRQ ID corresponding to @name upon success,
|
|
|
|
* or -ENOENT upon failure.
|
|
|
|
*/
|
|
|
|
int omap_prcm_event_to_irq(const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!prcm_irq_setup || !name)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
for (i = 0; i < prcm_irq_setup->nr_irqs; i++)
|
|
|
|
if (!strcmp(prcm_irq_setup->irqs[i].name, name))
|
|
|
|
return prcm_irq_setup->base_irq +
|
|
|
|
prcm_irq_setup->irqs[i].offset;
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_prcm_irq_cleanup - reverses memory allocated and other steps
|
|
|
|
* done by omap_prcm_register_chain_handler()
|
|
|
|
*
|
|
|
|
* No return value.
|
|
|
|
*/
|
|
|
|
void omap_prcm_irq_cleanup(void)
|
|
|
|
{
|
2015-01-17 10:21:08 +00:00
|
|
|
unsigned int irq;
|
2011-12-16 21:36:58 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!prcm_irq_setup) {
|
|
|
|
pr_err("PRCM: IRQ handler not initialized; cannot cleanup\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prcm_irq_chips) {
|
|
|
|
for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
|
|
|
|
if (prcm_irq_chips[i])
|
|
|
|
irq_remove_generic_chip(prcm_irq_chips[i],
|
|
|
|
0xffffffff, 0, 0);
|
|
|
|
prcm_irq_chips[i] = NULL;
|
|
|
|
}
|
|
|
|
kfree(prcm_irq_chips);
|
|
|
|
prcm_irq_chips = NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
kfree(prcm_irq_setup->saved_mask);
|
|
|
|
prcm_irq_setup->saved_mask = NULL;
|
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
kfree(prcm_irq_setup->priority_mask);
|
|
|
|
prcm_irq_setup->priority_mask = NULL;
|
|
|
|
|
2017-10-10 21:27:13 +00:00
|
|
|
irq = prcm_irq_setup->irq;
|
2015-01-17 10:21:08 +00:00
|
|
|
irq_set_chained_handler(irq, NULL);
|
2011-12-16 21:36:58 +00:00
|
|
|
|
|
|
|
if (prcm_irq_setup->base_irq > 0)
|
|
|
|
irq_free_descs(prcm_irq_setup->base_irq,
|
|
|
|
prcm_irq_setup->nr_regs * 32);
|
|
|
|
prcm_irq_setup->base_irq = 0;
|
|
|
|
}
|
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
void omap_prcm_irq_prepare(void)
|
|
|
|
{
|
|
|
|
prcm_irq_setup->suspended = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void omap_prcm_irq_complete(void)
|
|
|
|
{
|
|
|
|
prcm_irq_setup->suspended = false;
|
|
|
|
|
|
|
|
/* If we have not saved the masks, do not attempt to restore */
|
|
|
|
if (!prcm_irq_setup->suspend_save_flag)
|
|
|
|
return;
|
|
|
|
|
|
|
|
prcm_irq_setup->suspend_save_flag = false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-enable all masked PRCM irq sources, this causes the PRCM
|
|
|
|
* interrupt to fire immediately if the events were masked
|
|
|
|
* previously in the chain handler
|
|
|
|
*/
|
|
|
|
prcm_irq_setup->restore_irqen(prcm_irq_setup->saved_mask);
|
|
|
|
}
|
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
/**
|
|
|
|
* omap_prcm_register_chain_handler - initializes the prcm chained interrupt
|
|
|
|
* handler based on provided parameters
|
|
|
|
* @irq_setup: hardware data about the underlying PRM/PRCM
|
|
|
|
*
|
|
|
|
* Set up the PRCM chained interrupt handler on the PRCM IRQ. Sets up
|
|
|
|
* one generic IRQ chip per PRM interrupt status/enable register pair.
|
|
|
|
* Returns 0 upon success, -EINVAL if called twice or if invalid
|
|
|
|
* arguments are passed, or -ENOMEM on any other error.
|
|
|
|
*/
|
|
|
|
int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup)
|
|
|
|
{
|
2012-04-13 12:34:32 +00:00
|
|
|
int nr_regs;
|
2011-12-16 21:36:58 +00:00
|
|
|
u32 mask[OMAP_PRCM_MAX_NR_PENDING_REG];
|
2017-05-31 22:51:36 +00:00
|
|
|
int offset, i, irq;
|
2011-12-16 21:36:58 +00:00
|
|
|
struct irq_chip_generic *gc;
|
|
|
|
struct irq_chip_type *ct;
|
|
|
|
|
|
|
|
if (!irq_setup)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-04-13 12:34:32 +00:00
|
|
|
nr_regs = irq_setup->nr_regs;
|
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
if (prcm_irq_setup) {
|
|
|
|
pr_err("PRCM: already initialized; won't reinitialize\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nr_regs > OMAP_PRCM_MAX_NR_PENDING_REG) {
|
|
|
|
pr_err("PRCM: nr_regs too large\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
prcm_irq_setup = irq_setup;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 21:03:40 +00:00
|
|
|
prcm_irq_chips = kcalloc(nr_regs, sizeof(void *), GFP_KERNEL);
|
|
|
|
prcm_irq_setup->saved_mask = kcalloc(nr_regs, sizeof(u32),
|
|
|
|
GFP_KERNEL);
|
|
|
|
prcm_irq_setup->priority_mask = kcalloc(nr_regs, sizeof(u32),
|
|
|
|
GFP_KERNEL);
|
2011-12-16 21:36:58 +00:00
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
if (!prcm_irq_chips || !prcm_irq_setup->saved_mask ||
|
2016-12-03 20:46:02 +00:00
|
|
|
!prcm_irq_setup->priority_mask)
|
2011-12-16 21:36:58 +00:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
memset(mask, 0, sizeof(mask));
|
|
|
|
|
|
|
|
for (i = 0; i < irq_setup->nr_irqs; i++) {
|
|
|
|
offset = irq_setup->irqs[i].offset;
|
|
|
|
mask[offset >> 5] |= 1 << (offset & 0x1f);
|
|
|
|
if (irq_setup->irqs[i].priority)
|
|
|
|
irq_setup->priority_mask[offset >> 5] |=
|
|
|
|
1 << (offset & 0x1f);
|
|
|
|
}
|
|
|
|
|
2017-10-10 21:27:13 +00:00
|
|
|
irq = irq_setup->irq;
|
2015-01-17 10:21:08 +00:00
|
|
|
irq_set_chained_handler(irq, omap_prcm_irq_handler);
|
2011-12-16 21:36:58 +00:00
|
|
|
|
|
|
|
irq_setup->base_irq = irq_alloc_descs(-1, 0, irq_setup->nr_regs * 32,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (irq_setup->base_irq < 0) {
|
|
|
|
pr_err("PRCM: failed to allocate irq descs: %d\n",
|
|
|
|
irq_setup->base_irq);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:23:37 +00:00
|
|
|
for (i = 0; i < irq_setup->nr_regs; i++) {
|
2011-12-16 21:36:58 +00:00
|
|
|
gc = irq_alloc_generic_chip("PRCM", 1,
|
2017-05-31 15:00:00 +00:00
|
|
|
irq_setup->base_irq + i * 32, prm_base.va,
|
2011-12-16 21:36:58 +00:00
|
|
|
handle_level_irq);
|
|
|
|
|
|
|
|
if (!gc) {
|
|
|
|
pr_err("PRCM: failed to allocate generic chip\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
ct = gc->chip_types;
|
|
|
|
ct->chip.irq_ack = irq_gc_ack_set_bit;
|
|
|
|
ct->chip.irq_mask = irq_gc_mask_clr_bit;
|
|
|
|
ct->chip.irq_unmask = irq_gc_mask_set_bit;
|
|
|
|
|
|
|
|
ct->regs.ack = irq_setup->ack + i * 4;
|
|
|
|
ct->regs.mask = irq_setup->mask + i * 4;
|
|
|
|
|
|
|
|
irq_setup_generic_chip(gc, mask[i], 0, IRQ_NOREQUEST, 0);
|
|
|
|
prcm_irq_chips[i] = gc;
|
|
|
|
}
|
|
|
|
|
2017-05-31 22:51:36 +00:00
|
|
|
irq = omap_prcm_event_to_irq("io");
|
|
|
|
omap_pcs_legacy_init(irq, irq_setup->reconfigure_io_chain);
|
2013-10-10 22:45:13 +00:00
|
|
|
|
2011-12-16 21:36:58 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
omap_prcm_irq_cleanup();
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2012-07-04 11:04:00 +00:00
|
|
|
|
2012-10-30 02:57:39 +00:00
|
|
|
/**
|
|
|
|
* omap2_set_globals_prm - set the PRM base address (for early use)
|
|
|
|
* @prm: PRM base virtual address
|
|
|
|
*
|
|
|
|
* XXX Will be replaced when the PRM/CM drivers are completed.
|
2012-07-04 11:04:00 +00:00
|
|
|
*/
|
2012-10-30 02:57:39 +00:00
|
|
|
void __init omap2_set_globals_prm(void __iomem *prm)
|
2012-07-04 11:04:00 +00:00
|
|
|
{
|
2017-05-31 15:00:00 +00:00
|
|
|
prm_base.va = prm;
|
2012-07-04 11:04:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 07:01:13 +00:00
|
|
|
/**
|
|
|
|
* prm_read_reset_sources - return the sources of the SoC's last reset
|
|
|
|
*
|
|
|
|
* Return a u32 bitmask representing the reset sources that caused the
|
|
|
|
* SoC to reset. The low-level per-SoC functions called by this
|
|
|
|
* function remap the SoC-specific reset source bits into an
|
|
|
|
* OMAP-common set of reset source bits, defined in
|
|
|
|
* arch/arm/mach-omap2/prm.h. Returns the standardized reset source
|
|
|
|
* u32 bitmask from the hardware upon success, or returns (1 <<
|
|
|
|
* OMAP_UNKNOWN_RST_SRC_ID_SHIFT) if no low-level read_reset_sources()
|
|
|
|
* function was registered.
|
2012-07-04 11:04:00 +00:00
|
|
|
*/
|
2012-10-21 07:01:13 +00:00
|
|
|
u32 prm_read_reset_sources(void)
|
2012-07-04 11:04:00 +00:00
|
|
|
{
|
2012-10-21 07:01:13 +00:00
|
|
|
u32 ret = 1 << OMAP_UNKNOWN_RST_SRC_ID_SHIFT;
|
2012-07-04 11:04:00 +00:00
|
|
|
|
2012-10-21 07:01:13 +00:00
|
|
|
if (prm_ll_data->read_reset_sources)
|
|
|
|
ret = prm_ll_data->read_reset_sources();
|
|
|
|
else
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined for reset sources\n", __func__);
|
2012-07-04 11:04:00 +00:00
|
|
|
|
2012-10-21 07:01:13 +00:00
|
|
|
return ret;
|
2012-07-04 11:04:00 +00:00
|
|
|
}
|
|
|
|
|
ARM: OMAP2+: hwmod: Add support for per hwmod/module context lost count
OMAP4 has module specific context lost registers which makes it now
possible to have module level context loss count, instead of relying
on the powerdomain level context count.
Add 2 private hwmod api's to update/clear the hwmod/module specific
context lost counters/register.
Update the module specific context_lost_counter and clear the hardware
bits just after enabling the module.
omap_hwmod_get_context_loss_count() now returns the hwmod context loss
count them on platforms where they exist (OMAP4), else fall back on
the pwrdm level counters for older platforms.
Signed-off-by: Rajendra Nayak <rnayak@ti.com>
[paul@pwsan.com: added function kerneldoc, fixed structure kerneldoc,
rearranged structure to avoid memory waste, marked fns as OMAP4-specific,
prevent fn entry on non-OMAP4 chips, reduced indentation, merged update
and clear, merged patches]
[t-kristo@ti.com: added support for arch specific hwmod ops, and changed
the no context offset indicator to USHRT_MAX]
Signed-off-by: Tero Kristo <t-kristo@ti.com>
[paul@pwsan.com: use NO_CONTEXT_LOSS_BIT flag rather than USHRT_MAX;
convert unsigned context lost counter to int to match the return type;
get rid of hwmod_ops in favor of the existing soc_ops mechanism;
move context loss low-level accesses to the PRM code]
Signed-off-by: Paul Walmsley <paul@pwsan.com>
2012-11-21 23:15:17 +00:00
|
|
|
/**
|
|
|
|
* prm_was_any_context_lost_old - was device context lost? (old API)
|
|
|
|
* @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
|
|
|
|
* @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
|
|
|
|
* @idx: CONTEXT register offset
|
|
|
|
*
|
|
|
|
* Return 1 if any bits were set in the *_CONTEXT_* register
|
|
|
|
* identified by (@part, @inst, @idx), which means that some context
|
|
|
|
* was lost for that module; otherwise, return 0. XXX Deprecated;
|
|
|
|
* callers need to use a less-SoC-dependent way to identify hardware
|
|
|
|
* IP blocks.
|
|
|
|
*/
|
|
|
|
bool prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if (prm_ll_data->was_any_context_lost_old)
|
|
|
|
ret = prm_ll_data->was_any_context_lost_old(part, inst, idx);
|
|
|
|
else
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined\n",
|
|
|
|
__func__);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* prm_clear_context_lost_flags_old - clear context loss flags (old API)
|
|
|
|
* @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
|
|
|
|
* @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
|
|
|
|
* @idx: CONTEXT register offset
|
|
|
|
*
|
|
|
|
* Clear hardware context loss bits for the module identified by
|
|
|
|
* (@part, @inst, @idx). No return value. XXX Deprecated; callers
|
|
|
|
* need to use a less-SoC-dependent way to identify hardware IP
|
|
|
|
* blocks.
|
|
|
|
*/
|
|
|
|
void prm_clear_context_loss_flags_old(u8 part, s16 inst, u16 idx)
|
|
|
|
{
|
|
|
|
if (prm_ll_data->clear_context_loss_flags_old)
|
|
|
|
prm_ll_data->clear_context_loss_flags_old(part, inst, idx);
|
|
|
|
else
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined\n",
|
|
|
|
__func__);
|
|
|
|
}
|
|
|
|
|
2014-10-27 15:39:24 +00:00
|
|
|
/**
|
|
|
|
* omap_prm_assert_hardreset - assert hardreset for an IP block
|
|
|
|
* @shift: register bit shift corresponding to the reset line
|
|
|
|
* @part: PRM partition
|
|
|
|
* @prm_mod: PRM submodule base or instance offset
|
|
|
|
* @offset: register offset
|
|
|
|
*
|
|
|
|
* Asserts a hardware reset line for an IP block.
|
|
|
|
*/
|
|
|
|
int omap_prm_assert_hardreset(u8 shift, u8 part, s16 prm_mod, u16 offset)
|
|
|
|
{
|
|
|
|
if (!prm_ll_data->assert_hardreset) {
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined\n",
|
|
|
|
__func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prm_ll_data->assert_hardreset(shift, part, prm_mod, offset);
|
|
|
|
}
|
|
|
|
|
2014-10-27 15:39:25 +00:00
|
|
|
/**
|
|
|
|
* omap_prm_deassert_hardreset - deassert hardreset for an IP block
|
|
|
|
* @shift: register bit shift corresponding to the reset line
|
|
|
|
* @st_shift: reset status bit shift corresponding to the reset line
|
|
|
|
* @part: PRM partition
|
|
|
|
* @prm_mod: PRM submodule base or instance offset
|
|
|
|
* @offset: register offset
|
|
|
|
* @st_offset: status register offset
|
|
|
|
*
|
|
|
|
* Deasserts a hardware reset line for an IP block.
|
|
|
|
*/
|
|
|
|
int omap_prm_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 prm_mod,
|
|
|
|
u16 offset, u16 st_offset)
|
|
|
|
{
|
|
|
|
if (!prm_ll_data->deassert_hardreset) {
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined\n",
|
|
|
|
__func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prm_ll_data->deassert_hardreset(shift, st_shift, part, prm_mod,
|
|
|
|
offset, st_offset);
|
|
|
|
}
|
|
|
|
|
2014-10-27 15:39:25 +00:00
|
|
|
/**
|
|
|
|
* omap_prm_is_hardreset_asserted - check the hardreset status for an IP block
|
|
|
|
* @shift: register bit shift corresponding to the reset line
|
|
|
|
* @part: PRM partition
|
|
|
|
* @prm_mod: PRM submodule base or instance offset
|
|
|
|
* @offset: register offset
|
|
|
|
*
|
|
|
|
* Checks if a hardware reset line for an IP block is enabled or not.
|
|
|
|
*/
|
|
|
|
int omap_prm_is_hardreset_asserted(u8 shift, u8 part, s16 prm_mod, u16 offset)
|
|
|
|
{
|
|
|
|
if (!prm_ll_data->is_hardreset_asserted) {
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined\n",
|
|
|
|
__func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prm_ll_data->is_hardreset_asserted(shift, part, prm_mod, offset);
|
|
|
|
}
|
|
|
|
|
2014-10-27 15:39:26 +00:00
|
|
|
/**
|
|
|
|
* omap_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
|
|
|
|
*
|
|
|
|
* Clear any previously-latched I/O wakeup events and ensure that the
|
|
|
|
* I/O wakeup gates are aligned with the current mux settings.
|
|
|
|
* Calls SoC specific I/O chain reconfigure function if available,
|
|
|
|
* otherwise does nothing.
|
|
|
|
*/
|
|
|
|
void omap_prm_reconfigure_io_chain(void)
|
|
|
|
{
|
|
|
|
if (!prcm_irq_setup || !prcm_irq_setup->reconfigure_io_chain)
|
|
|
|
return;
|
|
|
|
|
|
|
|
prcm_irq_setup->reconfigure_io_chain();
|
|
|
|
}
|
|
|
|
|
2014-10-27 15:39:26 +00:00
|
|
|
/**
|
|
|
|
* omap_prm_reset_system - trigger global SW reset
|
|
|
|
*
|
|
|
|
* Triggers SoC specific global warm reset to reboot the device.
|
|
|
|
*/
|
|
|
|
void omap_prm_reset_system(void)
|
|
|
|
{
|
|
|
|
if (!prm_ll_data->reset_system) {
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined\n",
|
|
|
|
__func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
prm_ll_data->reset_system();
|
|
|
|
|
ARM: avoid Cortex-A9 livelock on tight dmb loops
machine_crash_nonpanic_core() does this:
while (1)
cpu_relax();
because the kernel has crashed, and we have no known safe way to deal
with the CPU. So, we place the CPU into an infinite loop which we
expect it to never exit - at least not until the system as a whole is
reset by some method.
In the absence of erratum 754327, this code assembles to:
b .
In other words, an infinite loop. When erratum 754327 is enabled,
this becomes:
1: dmb
b 1b
It has been observed that on some systems (eg, OMAP4) where, if a
crash is triggered, the system tries to kexec into the panic kernel,
but fails after taking the secondary CPU down - placing it into one
of these loops. This causes the system to livelock, and the most
noticable effect is the system stops after issuing:
Loading crashdump kernel...
to the system console.
The tested as working solution I came up with was to add wfe() to
these infinite loops thusly:
while (1) {
cpu_relax();
wfe();
}
which, without 754327 builds to:
1: wfe
b 1b
or with 754327 is enabled:
1: dmb
wfe
b 1b
Adding "wfe" does two things depending on the environment we're running
under:
- where we're running on bare metal, and the processor implements
"wfe", it stops us spinning endlessly in a loop where we're never
going to do any useful work.
- if we're running in a VM, it allows the CPU to be given back to the
hypervisor and rescheduled for other purposes (maybe a different VM)
rather than wasting CPU cycles inside a crashed VM.
However, in light of erratum 794072, Will Deacon wanted to see 10 nops
as well - which is reasonable to cover the case where we have erratum
754327 enabled _and_ we have a processor that doesn't implement the
wfe hint.
So, we now end up with:
1: wfe
b 1b
when erratum 754327 is disabled, or:
1: dmb
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
wfe
b 1b
when erratum 754327 is enabled. We also get the dmb + 10 nop
sequence elsewhere in the kernel, in terminating loops.
This is reasonable - it means we get the workaround for erratum
794072 when erratum 754327 is enabled, but still relinquish the dead
processor - either by placing it in a lower power mode when wfe is
implemented as such or by returning it to the hypervisior, or in the
case where wfe is a no-op, we use the workaround specified in erratum
794072 to avoid the problem.
These as two entirely orthogonal problems - the 10 nops addresses
erratum 794072, and the wfe is an optimisation that makes the system
more efficient when crashed either in terms of power consumption or
by allowing the host/other VMs to make use of the CPU.
I don't see any reason not to use kexec() inside a VM - it has the
potential to provide automated recovery from a failure of the VMs
kernel with the opportunity for saving a crashdump of the failure.
A panic() with a reboot timeout won't do that, and reading the
libvirt documentation, setting on_reboot to "preserve" won't either
(the documentation states "The preserve action for an on_reboot event
is treated as a destroy".) Surely it has to be a good thing to
avoiding having CPUs spinning inside a VM that is doing no useful
work.
Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2018-04-10 10:35:36 +00:00
|
|
|
while (1) {
|
2014-10-27 15:39:26 +00:00
|
|
|
cpu_relax();
|
ARM: avoid Cortex-A9 livelock on tight dmb loops
machine_crash_nonpanic_core() does this:
while (1)
cpu_relax();
because the kernel has crashed, and we have no known safe way to deal
with the CPU. So, we place the CPU into an infinite loop which we
expect it to never exit - at least not until the system as a whole is
reset by some method.
In the absence of erratum 754327, this code assembles to:
b .
In other words, an infinite loop. When erratum 754327 is enabled,
this becomes:
1: dmb
b 1b
It has been observed that on some systems (eg, OMAP4) where, if a
crash is triggered, the system tries to kexec into the panic kernel,
but fails after taking the secondary CPU down - placing it into one
of these loops. This causes the system to livelock, and the most
noticable effect is the system stops after issuing:
Loading crashdump kernel...
to the system console.
The tested as working solution I came up with was to add wfe() to
these infinite loops thusly:
while (1) {
cpu_relax();
wfe();
}
which, without 754327 builds to:
1: wfe
b 1b
or with 754327 is enabled:
1: dmb
wfe
b 1b
Adding "wfe" does two things depending on the environment we're running
under:
- where we're running on bare metal, and the processor implements
"wfe", it stops us spinning endlessly in a loop where we're never
going to do any useful work.
- if we're running in a VM, it allows the CPU to be given back to the
hypervisor and rescheduled for other purposes (maybe a different VM)
rather than wasting CPU cycles inside a crashed VM.
However, in light of erratum 794072, Will Deacon wanted to see 10 nops
as well - which is reasonable to cover the case where we have erratum
754327 enabled _and_ we have a processor that doesn't implement the
wfe hint.
So, we now end up with:
1: wfe
b 1b
when erratum 754327 is disabled, or:
1: dmb
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
wfe
b 1b
when erratum 754327 is enabled. We also get the dmb + 10 nop
sequence elsewhere in the kernel, in terminating loops.
This is reasonable - it means we get the workaround for erratum
794072 when erratum 754327 is enabled, but still relinquish the dead
processor - either by placing it in a lower power mode when wfe is
implemented as such or by returning it to the hypervisior, or in the
case where wfe is a no-op, we use the workaround specified in erratum
794072 to avoid the problem.
These as two entirely orthogonal problems - the 10 nops addresses
erratum 794072, and the wfe is an optimisation that makes the system
more efficient when crashed either in terms of power consumption or
by allowing the host/other VMs to make use of the CPU.
I don't see any reason not to use kexec() inside a VM - it has the
potential to provide automated recovery from a failure of the VMs
kernel with the opportunity for saving a crashdump of the failure.
A panic() with a reboot timeout won't do that, and reading the
libvirt documentation, setting on_reboot to "preserve" won't either
(the documentation states "The preserve action for an on_reboot event
is treated as a destroy".) Surely it has to be a good thing to
avoiding having CPUs spinning inside a VM that is doing no useful
work.
Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2018-04-10 10:35:36 +00:00
|
|
|
wfe();
|
|
|
|
}
|
2014-10-27 15:39:26 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 09:31:51 +00:00
|
|
|
/**
|
|
|
|
* omap_prm_clear_mod_irqs - clear wake-up events from PRCM interrupt
|
|
|
|
* @module: PRM module to clear wakeups from
|
|
|
|
* @regs: register to clear
|
|
|
|
* @wkst_mask: wkst bits to clear
|
|
|
|
*
|
|
|
|
* Clears any wakeup events for the module and register set defined.
|
|
|
|
* Uses SoC specific implementation to do the actual wakeup status
|
|
|
|
* clearing.
|
|
|
|
*/
|
|
|
|
int omap_prm_clear_mod_irqs(s16 module, u8 regs, u32 wkst_mask)
|
|
|
|
{
|
|
|
|
if (!prm_ll_data->clear_mod_irqs) {
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined\n",
|
|
|
|
__func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prm_ll_data->clear_mod_irqs(module, regs, wkst_mask);
|
|
|
|
}
|
|
|
|
|
2014-04-04 12:52:01 +00:00
|
|
|
/**
|
|
|
|
* omap_prm_vp_check_txdone - check voltage processor TX done status
|
|
|
|
*
|
|
|
|
* Checks if voltage processor transmission has been completed.
|
|
|
|
* Returns non-zero if a transmission has completed, 0 otherwise.
|
|
|
|
*/
|
|
|
|
u32 omap_prm_vp_check_txdone(u8 vp_id)
|
|
|
|
{
|
|
|
|
if (!prm_ll_data->vp_check_txdone) {
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined\n",
|
|
|
|
__func__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prm_ll_data->vp_check_txdone(vp_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_prm_vp_clear_txdone - clears voltage processor TX done status
|
|
|
|
*
|
|
|
|
* Clears the status bit for completed voltage processor transmission
|
|
|
|
* returned by prm_vp_check_txdone.
|
|
|
|
*/
|
|
|
|
void omap_prm_vp_clear_txdone(u8 vp_id)
|
|
|
|
{
|
|
|
|
if (!prm_ll_data->vp_clear_txdone) {
|
|
|
|
WARN_ONCE(1, "prm: %s: no mapping function defined\n",
|
|
|
|
__func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
prm_ll_data->vp_clear_txdone(vp_id);
|
|
|
|
}
|
|
|
|
|
ARM: OMAP2+: PRM: prepare for use of prm_ll_data function pointers
There are several PRM operations which behave similarly across OMAP2+
SoCs, but which have slight differences in their underlying
implementations. For example, to fetch the SoC's last reset sources,
different registers are read across OMAP2xxx, 3xxx, and 44xx, and
different bits are used on each SoC. But the information returned is
so similar that a single, common interface for drivers is useful.
This patch creates the support code for this function pointer
registration process. No function pointers are included yet, but a
subsequent patch will create one for the reset source API.
To illustrate the end goal with the above reset source example, each
per-SoC driver will use its own low-level implementation function --
e.g., prm2xxx.c would contain omap2xxx_prm_read_reset_sources(). This
function would read the appropriate register and remap the register
bits to a standard set of reset source bits. When the prm2xxx.c
driver is loaded, it would register this function with the common PRM
driver, prm.c. prm.c would then export a common function,
omap_prm_read_reset_sources(). Calling it would call through to the
function pointer for the currently-registered SoC PRM driver. This
will allow other drivers to use PRM-provided data and operations
without needing to know which SoC is currently in use.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
2012-10-21 07:01:11 +00:00
|
|
|
/**
|
|
|
|
* prm_register - register per-SoC low-level data with the PRM
|
|
|
|
* @pld: low-level per-SoC OMAP PRM data & function pointers to register
|
|
|
|
*
|
|
|
|
* Register per-SoC low-level OMAP PRM data and function pointers with
|
|
|
|
* the OMAP PRM common interface. The caller must keep the data
|
|
|
|
* pointed to by @pld valid until it calls prm_unregister() and
|
|
|
|
* it returns successfully. Returns 0 upon success, -EINVAL if @pld
|
|
|
|
* is NULL, or -EEXIST if prm_register() has already been called
|
|
|
|
* without an intervening prm_unregister().
|
|
|
|
*/
|
|
|
|
int prm_register(struct prm_ll_data *pld)
|
2012-07-04 11:04:00 +00:00
|
|
|
{
|
ARM: OMAP2+: PRM: prepare for use of prm_ll_data function pointers
There are several PRM operations which behave similarly across OMAP2+
SoCs, but which have slight differences in their underlying
implementations. For example, to fetch the SoC's last reset sources,
different registers are read across OMAP2xxx, 3xxx, and 44xx, and
different bits are used on each SoC. But the information returned is
so similar that a single, common interface for drivers is useful.
This patch creates the support code for this function pointer
registration process. No function pointers are included yet, but a
subsequent patch will create one for the reset source API.
To illustrate the end goal with the above reset source example, each
per-SoC driver will use its own low-level implementation function --
e.g., prm2xxx.c would contain omap2xxx_prm_read_reset_sources(). This
function would read the appropriate register and remap the register
bits to a standard set of reset source bits. When the prm2xxx.c
driver is loaded, it would register this function with the common PRM
driver, prm.c. prm.c would then export a common function,
omap_prm_read_reset_sources(). Calling it would call through to the
function pointer for the currently-registered SoC PRM driver. This
will allow other drivers to use PRM-provided data and operations
without needing to know which SoC is currently in use.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
2012-10-21 07:01:11 +00:00
|
|
|
if (!pld)
|
|
|
|
return -EINVAL;
|
2012-07-04 11:04:00 +00:00
|
|
|
|
ARM: OMAP2+: PRM: prepare for use of prm_ll_data function pointers
There are several PRM operations which behave similarly across OMAP2+
SoCs, but which have slight differences in their underlying
implementations. For example, to fetch the SoC's last reset sources,
different registers are read across OMAP2xxx, 3xxx, and 44xx, and
different bits are used on each SoC. But the information returned is
so similar that a single, common interface for drivers is useful.
This patch creates the support code for this function pointer
registration process. No function pointers are included yet, but a
subsequent patch will create one for the reset source API.
To illustrate the end goal with the above reset source example, each
per-SoC driver will use its own low-level implementation function --
e.g., prm2xxx.c would contain omap2xxx_prm_read_reset_sources(). This
function would read the appropriate register and remap the register
bits to a standard set of reset source bits. When the prm2xxx.c
driver is loaded, it would register this function with the common PRM
driver, prm.c. prm.c would then export a common function,
omap_prm_read_reset_sources(). Calling it would call through to the
function pointer for the currently-registered SoC PRM driver. This
will allow other drivers to use PRM-provided data and operations
without needing to know which SoC is currently in use.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
2012-10-21 07:01:11 +00:00
|
|
|
if (prm_ll_data != &null_prm_ll_data)
|
|
|
|
return -EEXIST;
|
2012-07-04 11:04:00 +00:00
|
|
|
|
ARM: OMAP2+: PRM: prepare for use of prm_ll_data function pointers
There are several PRM operations which behave similarly across OMAP2+
SoCs, but which have slight differences in their underlying
implementations. For example, to fetch the SoC's last reset sources,
different registers are read across OMAP2xxx, 3xxx, and 44xx, and
different bits are used on each SoC. But the information returned is
so similar that a single, common interface for drivers is useful.
This patch creates the support code for this function pointer
registration process. No function pointers are included yet, but a
subsequent patch will create one for the reset source API.
To illustrate the end goal with the above reset source example, each
per-SoC driver will use its own low-level implementation function --
e.g., prm2xxx.c would contain omap2xxx_prm_read_reset_sources(). This
function would read the appropriate register and remap the register
bits to a standard set of reset source bits. When the prm2xxx.c
driver is loaded, it would register this function with the common PRM
driver, prm.c. prm.c would then export a common function,
omap_prm_read_reset_sources(). Calling it would call through to the
function pointer for the currently-registered SoC PRM driver. This
will allow other drivers to use PRM-provided data and operations
without needing to know which SoC is currently in use.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
2012-10-21 07:01:11 +00:00
|
|
|
prm_ll_data = pld;
|
2012-07-04 11:04:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
ARM: OMAP2+: PRM: prepare for use of prm_ll_data function pointers
There are several PRM operations which behave similarly across OMAP2+
SoCs, but which have slight differences in their underlying
implementations. For example, to fetch the SoC's last reset sources,
different registers are read across OMAP2xxx, 3xxx, and 44xx, and
different bits are used on each SoC. But the information returned is
so similar that a single, common interface for drivers is useful.
This patch creates the support code for this function pointer
registration process. No function pointers are included yet, but a
subsequent patch will create one for the reset source API.
To illustrate the end goal with the above reset source example, each
per-SoC driver will use its own low-level implementation function --
e.g., prm2xxx.c would contain omap2xxx_prm_read_reset_sources(). This
function would read the appropriate register and remap the register
bits to a standard set of reset source bits. When the prm2xxx.c
driver is loaded, it would register this function with the common PRM
driver, prm.c. prm.c would then export a common function,
omap_prm_read_reset_sources(). Calling it would call through to the
function pointer for the currently-registered SoC PRM driver. This
will allow other drivers to use PRM-provided data and operations
without needing to know which SoC is currently in use.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
2012-10-21 07:01:11 +00:00
|
|
|
/**
|
|
|
|
* prm_unregister - unregister per-SoC low-level data & function pointers
|
|
|
|
* @pld: low-level per-SoC OMAP PRM data & function pointers to unregister
|
|
|
|
*
|
|
|
|
* Unregister per-SoC low-level OMAP PRM data and function pointers
|
|
|
|
* that were previously registered with prm_register(). The
|
|
|
|
* caller may not destroy any of the data pointed to by @pld until
|
|
|
|
* this function returns successfully. Returns 0 upon success, or
|
|
|
|
* -EINVAL if @pld is NULL or if @pld does not match the struct
|
|
|
|
* prm_ll_data * previously registered by prm_register().
|
|
|
|
*/
|
|
|
|
int prm_unregister(struct prm_ll_data *pld)
|
2012-07-04 11:04:00 +00:00
|
|
|
{
|
ARM: OMAP2+: PRM: prepare for use of prm_ll_data function pointers
There are several PRM operations which behave similarly across OMAP2+
SoCs, but which have slight differences in their underlying
implementations. For example, to fetch the SoC's last reset sources,
different registers are read across OMAP2xxx, 3xxx, and 44xx, and
different bits are used on each SoC. But the information returned is
so similar that a single, common interface for drivers is useful.
This patch creates the support code for this function pointer
registration process. No function pointers are included yet, but a
subsequent patch will create one for the reset source API.
To illustrate the end goal with the above reset source example, each
per-SoC driver will use its own low-level implementation function --
e.g., prm2xxx.c would contain omap2xxx_prm_read_reset_sources(). This
function would read the appropriate register and remap the register
bits to a standard set of reset source bits. When the prm2xxx.c
driver is loaded, it would register this function with the common PRM
driver, prm.c. prm.c would then export a common function,
omap_prm_read_reset_sources(). Calling it would call through to the
function pointer for the currently-registered SoC PRM driver. This
will allow other drivers to use PRM-provided data and operations
without needing to know which SoC is currently in use.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
2012-10-21 07:01:11 +00:00
|
|
|
if (!pld || prm_ll_data != pld)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
prm_ll_data = &null_prm_ll_data;
|
2012-07-04 11:04:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-10-25 12:28:11 +00:00
|
|
|
|
2014-11-20 13:02:59 +00:00
|
|
|
#ifdef CONFIG_ARCH_OMAP2
|
|
|
|
static struct omap_prcm_init_data omap2_prm_data __initdata = {
|
2015-02-23 13:57:32 +00:00
|
|
|
.index = TI_CLKM_PRM,
|
2014-11-20 13:02:59 +00:00
|
|
|
.init = omap2xxx_prm_init,
|
2015-02-23 13:57:32 +00:00
|
|
|
};
|
2014-11-20 13:02:59 +00:00
|
|
|
#endif
|
2015-02-23 13:57:32 +00:00
|
|
|
|
2014-11-20 13:02:59 +00:00
|
|
|
#ifdef CONFIG_ARCH_OMAP3
|
|
|
|
static struct omap_prcm_init_data omap3_prm_data __initdata = {
|
2014-11-11 15:17:18 +00:00
|
|
|
.index = TI_CLKM_PRM,
|
2014-11-20 13:02:59 +00:00
|
|
|
.init = omap3xxx_prm_init,
|
2014-11-11 15:17:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IVA2 offset is a negative value, must offset the prm_base
|
|
|
|
* address by this to get it to positive
|
|
|
|
*/
|
|
|
|
.offset = -OMAP3430_IVA2_MOD,
|
|
|
|
};
|
2014-11-20 13:02:59 +00:00
|
|
|
#endif
|
2014-11-11 15:17:18 +00:00
|
|
|
|
2014-11-20 13:02:59 +00:00
|
|
|
#if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_TI81XX)
|
|
|
|
static struct omap_prcm_init_data am3_prm_data __initdata = {
|
|
|
|
.index = TI_CLKM_PRM,
|
|
|
|
.init = am33xx_prm_init,
|
|
|
|
};
|
2015-12-21 18:06:52 +00:00
|
|
|
#endif
|
2015-12-03 20:02:31 +00:00
|
|
|
|
2015-12-21 18:06:52 +00:00
|
|
|
#ifdef CONFIG_SOC_TI81XX
|
2015-12-03 20:02:31 +00:00
|
|
|
static struct omap_prcm_init_data dm814_pllss_data __initdata = {
|
|
|
|
.index = TI_CLKM_PLLSS,
|
|
|
|
.init = am33xx_prm_init,
|
|
|
|
};
|
2014-11-20 13:02:59 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-08 08:29:43 +00:00
|
|
|
#ifdef CONFIG_ARCH_OMAP4
|
2014-11-20 13:02:59 +00:00
|
|
|
static struct omap_prcm_init_data omap4_prm_data __initdata = {
|
|
|
|
.index = TI_CLKM_PRM,
|
|
|
|
.init = omap44xx_prm_init,
|
2014-09-08 08:29:43 +00:00
|
|
|
.device_inst_offset = OMAP4430_PRM_DEVICE_INST,
|
2017-10-10 21:27:13 +00:00
|
|
|
.flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
|
2014-09-08 08:29:43 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SOC_OMAP5
|
|
|
|
static struct omap_prcm_init_data omap5_prm_data __initdata = {
|
|
|
|
.index = TI_CLKM_PRM,
|
|
|
|
.init = omap44xx_prm_init,
|
|
|
|
.device_inst_offset = OMAP54XX_PRM_DEVICE_INST,
|
2014-11-21 12:45:29 +00:00
|
|
|
.flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
|
2014-09-08 08:29:43 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SOC_DRA7XX
|
|
|
|
static struct omap_prcm_init_data dra7_prm_data __initdata = {
|
|
|
|
.index = TI_CLKM_PRM,
|
|
|
|
.init = omap44xx_prm_init,
|
|
|
|
.device_inst_offset = DRA7XX_PRM_DEVICE_INST,
|
2014-11-21 12:45:29 +00:00
|
|
|
.flags = PRM_HAS_IO_WAKEUP,
|
2014-09-08 08:29:43 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SOC_AM43XX
|
|
|
|
static struct omap_prcm_init_data am4_prm_data __initdata = {
|
|
|
|
.index = TI_CLKM_PRM,
|
|
|
|
.init = omap44xx_prm_init,
|
|
|
|
.device_inst_offset = AM43XX_PRM_DEVICE_INST,
|
2015-07-16 11:53:19 +00:00
|
|
|
.flags = PRM_HAS_IO_WAKEUP,
|
2015-02-23 13:57:32 +00:00
|
|
|
};
|
2014-11-20 13:02:59 +00:00
|
|
|
#endif
|
2015-02-23 13:57:32 +00:00
|
|
|
|
2014-11-20 13:02:59 +00:00
|
|
|
#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
|
|
|
|
static struct omap_prcm_init_data scrm_data __initdata = {
|
|
|
|
.index = TI_CLKM_SCRM,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2017-05-11 11:50:16 +00:00
|
|
|
static const struct of_device_id omap_prcm_dt_match_table[] __initconst = {
|
2014-11-20 13:02:59 +00:00
|
|
|
#ifdef CONFIG_SOC_AM33XX
|
|
|
|
{ .compatible = "ti,am3-prcm", .data = &am3_prm_data },
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SOC_AM43XX
|
2014-09-08 08:29:43 +00:00
|
|
|
{ .compatible = "ti,am4-prcm", .data = &am4_prm_data },
|
2014-11-20 13:02:59 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SOC_TI81XX
|
|
|
|
{ .compatible = "ti,dm814-prcm", .data = &am3_prm_data },
|
2015-12-03 20:02:31 +00:00
|
|
|
{ .compatible = "ti,dm814-pllss", .data = &dm814_pllss_data },
|
2014-11-20 13:02:59 +00:00
|
|
|
{ .compatible = "ti,dm816-prcm", .data = &am3_prm_data },
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ARCH_OMAP2
|
|
|
|
{ .compatible = "ti,omap2-prcm", .data = &omap2_prm_data },
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ARCH_OMAP3
|
2014-11-11 15:17:18 +00:00
|
|
|
{ .compatible = "ti,omap3-prm", .data = &omap3_prm_data },
|
2014-11-20 13:02:59 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ARCH_OMAP4
|
|
|
|
{ .compatible = "ti,omap4-prm", .data = &omap4_prm_data },
|
2015-02-23 13:57:32 +00:00
|
|
|
{ .compatible = "ti,omap4-scrm", .data = &scrm_data },
|
2014-11-20 13:02:59 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SOC_OMAP5
|
2014-09-08 08:29:43 +00:00
|
|
|
{ .compatible = "ti,omap5-prm", .data = &omap5_prm_data },
|
2015-02-23 13:57:32 +00:00
|
|
|
{ .compatible = "ti,omap5-scrm", .data = &scrm_data },
|
2014-11-20 13:02:59 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SOC_DRA7XX
|
2014-09-08 08:29:43 +00:00
|
|
|
{ .compatible = "ti,dra7-prm", .data = &dra7_prm_data },
|
2014-11-20 13:02:59 +00:00
|
|
|
#endif
|
2013-10-25 12:28:11 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2014-11-11 15:17:18 +00:00
|
|
|
/**
|
|
|
|
* omap2_prm_base_init - initialize iomappings for the PRM driver
|
|
|
|
*
|
|
|
|
* Detects and initializes the iomappings for the PRM driver, based
|
|
|
|
* on the DT data. Returns 0 in success, negative error value
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
int __init omap2_prm_base_init(void)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
const struct of_device_id *match;
|
|
|
|
struct omap_prcm_init_data *data;
|
2017-05-31 15:00:00 +00:00
|
|
|
struct resource res;
|
|
|
|
int ret;
|
2014-11-11 15:17:18 +00:00
|
|
|
|
|
|
|
for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
|
|
|
|
data = (struct omap_prcm_init_data *)match->data;
|
|
|
|
|
2017-05-31 15:00:00 +00:00
|
|
|
ret = of_address_to_resource(np, 0, &res);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-11-11 15:17:18 +00:00
|
|
|
|
2017-05-31 15:00:00 +00:00
|
|
|
data->mem = ioremap(res.start, resource_size(&res));
|
2014-11-11 15:17:18 +00:00
|
|
|
|
2017-05-31 15:00:00 +00:00
|
|
|
if (data->index == TI_CLKM_PRM) {
|
|
|
|
prm_base.va = data->mem + data->offset;
|
|
|
|
prm_base.pa = res.start + data->offset;
|
|
|
|
}
|
2014-11-20 13:02:59 +00:00
|
|
|
|
|
|
|
data->np = np;
|
|
|
|
|
|
|
|
if (data->init)
|
|
|
|
data->init(data);
|
2014-11-11 15:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-20 13:02:59 +00:00
|
|
|
int __init omap2_prcm_base_init(void)
|
|
|
|
{
|
2014-11-21 13:51:37 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = omap2_prm_base_init();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return omap2_cm_base_init();
|
2014-11-20 13:02:59 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 12:59:36 +00:00
|
|
|
/**
|
|
|
|
* omap_prcm_init - low level init for the PRCM drivers
|
|
|
|
*
|
|
|
|
* Initializes the low level clock infrastructure for PRCM drivers.
|
|
|
|
* Returns 0 in success, negative error value in failure.
|
|
|
|
*/
|
|
|
|
int __init omap_prcm_init(void)
|
2013-10-25 12:28:11 +00:00
|
|
|
{
|
|
|
|
struct device_node *np;
|
2015-02-23 13:57:32 +00:00
|
|
|
const struct of_device_id *match;
|
|
|
|
const struct omap_prcm_init_data *data;
|
2014-10-22 12:15:36 +00:00
|
|
|
int ret;
|
2013-10-25 12:28:11 +00:00
|
|
|
|
2015-02-23 13:57:32 +00:00
|
|
|
for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
|
|
|
|
data = match->data;
|
|
|
|
|
2015-02-06 14:00:32 +00:00
|
|
|
ret = omap2_clk_provider_init(np, data->index, NULL, data->mem);
|
2014-10-22 12:15:36 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2013-10-25 12:28:11 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 16:33:45 +00:00
|
|
|
omap_cm_init();
|
|
|
|
|
2013-10-25 12:28:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-03-31 15:15:45 +00:00
|
|
|
|
|
|
|
static int __init prm_late_init(void)
|
|
|
|
{
|
|
|
|
if (prm_ll_data->late_init)
|
|
|
|
return prm_ll_data->late_init();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
subsys_initcall(prm_late_init);
|