10a84a91cSTero Kristo /* 20a84a91cSTero Kristo * OMAP2+ common Power & Reset Management (PRM) IP block functions 30a84a91cSTero Kristo * 40a84a91cSTero Kristo * Copyright (C) 2011 Texas Instruments, Inc. 50a84a91cSTero Kristo * Tero Kristo <t-kristo@ti.com> 60a84a91cSTero Kristo * 70a84a91cSTero Kristo * This program is free software; you can redistribute it and/or modify 80a84a91cSTero Kristo * it under the terms of the GNU General Public License version 2 as 90a84a91cSTero Kristo * published by the Free Software Foundation. 100a84a91cSTero Kristo * 110a84a91cSTero Kristo * 120a84a91cSTero Kristo * For historical purposes, the API used to configure the PRM 130a84a91cSTero Kristo * interrupt handler refers to it as the "PRCM interrupt." The 140a84a91cSTero Kristo * underlying registers are located in the PRM on OMAP3/4. 150a84a91cSTero Kristo * 160a84a91cSTero Kristo * XXX This code should eventually be moved to a PRM driver. 170a84a91cSTero Kristo */ 180a84a91cSTero Kristo 190a84a91cSTero Kristo #include <linux/kernel.h> 200a84a91cSTero Kristo #include <linux/module.h> 210a84a91cSTero Kristo #include <linux/init.h> 220a84a91cSTero Kristo #include <linux/io.h> 230a84a91cSTero Kristo #include <linux/irq.h> 240a84a91cSTero Kristo #include <linux/interrupt.h> 250a84a91cSTero Kristo #include <linux/slab.h> 260a84a91cSTero Kristo 27*30a69ef7STony Lindgren #include "soc.h" 280a84a91cSTero Kristo #include "prm2xxx_3xxx.h" 292bb2a5d3SPaul Walmsley #include "prm2xxx.h" 302bb2a5d3SPaul Walmsley #include "prm3xxx.h" 310a84a91cSTero Kristo #include "prm44xx.h" 32d9a16f9aSPaul Walmsley #include "common.h" 330a84a91cSTero Kristo 340a84a91cSTero Kristo /* 350a84a91cSTero Kristo * OMAP_PRCM_MAX_NR_PENDING_REG: maximum number of PRM_IRQ*_MPU regs 360a84a91cSTero Kristo * XXX this is technically not needed, since 370a84a91cSTero Kristo * omap_prcm_register_chain_handler() could allocate this based on the 380a84a91cSTero Kristo * actual amount of memory needed for the SoC 390a84a91cSTero Kristo */ 400a84a91cSTero Kristo #define OMAP_PRCM_MAX_NR_PENDING_REG 2 410a84a91cSTero Kristo 420a84a91cSTero Kristo /* 430a84a91cSTero Kristo * prcm_irq_chips: an array of all of the "generic IRQ chips" in use 440a84a91cSTero Kristo * by the PRCM interrupt handler code. There will be one 'chip' per 450a84a91cSTero Kristo * PRM_{IRQSTATUS,IRQENABLE}_MPU register pair. (So OMAP3 will have 460a84a91cSTero Kristo * one "chip" and OMAP4 will have two.) 470a84a91cSTero Kristo */ 480a84a91cSTero Kristo static struct irq_chip_generic **prcm_irq_chips; 490a84a91cSTero Kristo 500a84a91cSTero Kristo /* 510a84a91cSTero Kristo * prcm_irq_setup: the PRCM IRQ parameters for the hardware the code 520a84a91cSTero Kristo * is currently running on. Defined and passed by initialization code 530a84a91cSTero Kristo * that calls omap_prcm_register_chain_handler(). 540a84a91cSTero Kristo */ 550a84a91cSTero Kristo static struct omap_prcm_irq_setup *prcm_irq_setup; 560a84a91cSTero Kristo 57d9a16f9aSPaul Walmsley /* prm_base: base virtual address of the PRM IP block */ 58d9a16f9aSPaul Walmsley void __iomem *prm_base; 59d9a16f9aSPaul Walmsley 60e24c3573SPaul Walmsley /* 61e24c3573SPaul Walmsley * prm_ll_data: function pointers to SoC-specific implementations of 62e24c3573SPaul Walmsley * common PRM functions 63e24c3573SPaul Walmsley */ 64e24c3573SPaul Walmsley static struct prm_ll_data null_prm_ll_data; 65e24c3573SPaul Walmsley static struct prm_ll_data *prm_ll_data = &null_prm_ll_data; 66e24c3573SPaul Walmsley 670a84a91cSTero Kristo /* Private functions */ 680a84a91cSTero Kristo 690a84a91cSTero Kristo /* 700a84a91cSTero Kristo * Move priority events from events to priority_events array 710a84a91cSTero Kristo */ 720a84a91cSTero Kristo static void omap_prcm_events_filter_priority(unsigned long *events, 730a84a91cSTero Kristo unsigned long *priority_events) 740a84a91cSTero Kristo { 750a84a91cSTero Kristo int i; 760a84a91cSTero Kristo 770a84a91cSTero Kristo for (i = 0; i < prcm_irq_setup->nr_regs; i++) { 780a84a91cSTero Kristo priority_events[i] = 790a84a91cSTero Kristo events[i] & prcm_irq_setup->priority_mask[i]; 800a84a91cSTero Kristo events[i] ^= priority_events[i]; 810a84a91cSTero Kristo } 820a84a91cSTero Kristo } 830a84a91cSTero Kristo 840a84a91cSTero Kristo /* 850a84a91cSTero Kristo * PRCM Interrupt Handler 860a84a91cSTero Kristo * 870a84a91cSTero Kristo * This is a common handler for the OMAP PRCM interrupts. Pending 880a84a91cSTero Kristo * interrupts are detected by a call to prcm_pending_events and 890a84a91cSTero Kristo * dispatched accordingly. Clearing of the wakeup events should be 900a84a91cSTero Kristo * done by the SoC specific individual handlers. 910a84a91cSTero Kristo */ 920a84a91cSTero Kristo static void omap_prcm_irq_handler(unsigned int irq, struct irq_desc *desc) 930a84a91cSTero Kristo { 940a84a91cSTero Kristo unsigned long pending[OMAP_PRCM_MAX_NR_PENDING_REG]; 950a84a91cSTero Kristo unsigned long priority_pending[OMAP_PRCM_MAX_NR_PENDING_REG]; 960a84a91cSTero Kristo struct irq_chip *chip = irq_desc_get_chip(desc); 970a84a91cSTero Kristo unsigned int virtirq; 98b56f2cb7SVenkatraman S int nr_irq = prcm_irq_setup->nr_regs * 32; 990a84a91cSTero Kristo 1000a84a91cSTero Kristo /* 10191285b6fSTero Kristo * If we are suspended, mask all interrupts from PRCM level, 10291285b6fSTero Kristo * this does not ack them, and they will be pending until we 10391285b6fSTero Kristo * re-enable the interrupts, at which point the 10491285b6fSTero Kristo * omap_prcm_irq_handler will be executed again. The 10591285b6fSTero Kristo * _save_and_clear_irqen() function must ensure that the PRM 10691285b6fSTero Kristo * write to disable all IRQs has reached the PRM before 10791285b6fSTero Kristo * returning, or spurious PRCM interrupts may occur during 10891285b6fSTero Kristo * suspend. 10991285b6fSTero Kristo */ 11091285b6fSTero Kristo if (prcm_irq_setup->suspended) { 11191285b6fSTero Kristo prcm_irq_setup->save_and_clear_irqen(prcm_irq_setup->saved_mask); 11291285b6fSTero Kristo prcm_irq_setup->suspend_save_flag = true; 11391285b6fSTero Kristo } 11491285b6fSTero Kristo 11591285b6fSTero Kristo /* 1160a84a91cSTero Kristo * Loop until all pending irqs are handled, since 1170a84a91cSTero Kristo * generic_handle_irq() can cause new irqs to come 1180a84a91cSTero Kristo */ 11991285b6fSTero Kristo while (!prcm_irq_setup->suspended) { 1200a84a91cSTero Kristo prcm_irq_setup->read_pending_irqs(pending); 1210a84a91cSTero Kristo 1220a84a91cSTero Kristo /* No bit set, then all IRQs are handled */ 123b56f2cb7SVenkatraman S if (find_first_bit(pending, nr_irq) >= nr_irq) 1240a84a91cSTero Kristo break; 1250a84a91cSTero Kristo 1260a84a91cSTero Kristo omap_prcm_events_filter_priority(pending, priority_pending); 1270a84a91cSTero Kristo 1280a84a91cSTero Kristo /* 1290a84a91cSTero Kristo * Loop on all currently pending irqs so that new irqs 1300a84a91cSTero Kristo * cannot starve previously pending irqs 1310a84a91cSTero Kristo */ 1320a84a91cSTero Kristo 1330a84a91cSTero Kristo /* Serve priority events first */ 134b56f2cb7SVenkatraman S for_each_set_bit(virtirq, priority_pending, nr_irq) 1350a84a91cSTero Kristo generic_handle_irq(prcm_irq_setup->base_irq + virtirq); 1360a84a91cSTero Kristo 1370a84a91cSTero Kristo /* Serve normal events next */ 138b56f2cb7SVenkatraman S for_each_set_bit(virtirq, pending, nr_irq) 1390a84a91cSTero Kristo generic_handle_irq(prcm_irq_setup->base_irq + virtirq); 1400a84a91cSTero Kristo } 1410a84a91cSTero Kristo if (chip->irq_ack) 1420a84a91cSTero Kristo chip->irq_ack(&desc->irq_data); 1430a84a91cSTero Kristo if (chip->irq_eoi) 1440a84a91cSTero Kristo chip->irq_eoi(&desc->irq_data); 1450a84a91cSTero Kristo chip->irq_unmask(&desc->irq_data); 1460a84a91cSTero Kristo 1470a84a91cSTero Kristo prcm_irq_setup->ocp_barrier(); /* avoid spurious IRQs */ 1480a84a91cSTero Kristo } 1490a84a91cSTero Kristo 1500a84a91cSTero Kristo /* Public functions */ 1510a84a91cSTero Kristo 1520a84a91cSTero Kristo /** 1530a84a91cSTero Kristo * omap_prcm_event_to_irq - given a PRCM event name, returns the 1540a84a91cSTero Kristo * corresponding IRQ on which the handler should be registered 1550a84a91cSTero Kristo * @name: name of the PRCM interrupt bit to look up - see struct omap_prcm_irq 1560a84a91cSTero Kristo * 1570a84a91cSTero Kristo * Returns the Linux internal IRQ ID corresponding to @name upon success, 1580a84a91cSTero Kristo * or -ENOENT upon failure. 1590a84a91cSTero Kristo */ 1600a84a91cSTero Kristo int omap_prcm_event_to_irq(const char *name) 1610a84a91cSTero Kristo { 1620a84a91cSTero Kristo int i; 1630a84a91cSTero Kristo 1640a84a91cSTero Kristo if (!prcm_irq_setup || !name) 1650a84a91cSTero Kristo return -ENOENT; 1660a84a91cSTero Kristo 1670a84a91cSTero Kristo for (i = 0; i < prcm_irq_setup->nr_irqs; i++) 1680a84a91cSTero Kristo if (!strcmp(prcm_irq_setup->irqs[i].name, name)) 1690a84a91cSTero Kristo return prcm_irq_setup->base_irq + 1700a84a91cSTero Kristo prcm_irq_setup->irqs[i].offset; 1710a84a91cSTero Kristo 1720a84a91cSTero Kristo return -ENOENT; 1730a84a91cSTero Kristo } 1740a84a91cSTero Kristo 1750a84a91cSTero Kristo /** 1760a84a91cSTero Kristo * omap_prcm_irq_cleanup - reverses memory allocated and other steps 1770a84a91cSTero Kristo * done by omap_prcm_register_chain_handler() 1780a84a91cSTero Kristo * 1790a84a91cSTero Kristo * No return value. 1800a84a91cSTero Kristo */ 1810a84a91cSTero Kristo void omap_prcm_irq_cleanup(void) 1820a84a91cSTero Kristo { 1830a84a91cSTero Kristo int i; 1840a84a91cSTero Kristo 1850a84a91cSTero Kristo if (!prcm_irq_setup) { 1860a84a91cSTero Kristo pr_err("PRCM: IRQ handler not initialized; cannot cleanup\n"); 1870a84a91cSTero Kristo return; 1880a84a91cSTero Kristo } 1890a84a91cSTero Kristo 1900a84a91cSTero Kristo if (prcm_irq_chips) { 1910a84a91cSTero Kristo for (i = 0; i < prcm_irq_setup->nr_regs; i++) { 1920a84a91cSTero Kristo if (prcm_irq_chips[i]) 1930a84a91cSTero Kristo irq_remove_generic_chip(prcm_irq_chips[i], 1940a84a91cSTero Kristo 0xffffffff, 0, 0); 1950a84a91cSTero Kristo prcm_irq_chips[i] = NULL; 1960a84a91cSTero Kristo } 1970a84a91cSTero Kristo kfree(prcm_irq_chips); 1980a84a91cSTero Kristo prcm_irq_chips = NULL; 1990a84a91cSTero Kristo } 2000a84a91cSTero Kristo 20191285b6fSTero Kristo kfree(prcm_irq_setup->saved_mask); 20291285b6fSTero Kristo prcm_irq_setup->saved_mask = NULL; 20391285b6fSTero Kristo 2040a84a91cSTero Kristo kfree(prcm_irq_setup->priority_mask); 2050a84a91cSTero Kristo prcm_irq_setup->priority_mask = NULL; 2060a84a91cSTero Kristo 2070a84a91cSTero Kristo irq_set_chained_handler(prcm_irq_setup->irq, NULL); 2080a84a91cSTero Kristo 2090a84a91cSTero Kristo if (prcm_irq_setup->base_irq > 0) 2100a84a91cSTero Kristo irq_free_descs(prcm_irq_setup->base_irq, 2110a84a91cSTero Kristo prcm_irq_setup->nr_regs * 32); 2120a84a91cSTero Kristo prcm_irq_setup->base_irq = 0; 2130a84a91cSTero Kristo } 2140a84a91cSTero Kristo 21591285b6fSTero Kristo void omap_prcm_irq_prepare(void) 21691285b6fSTero Kristo { 21791285b6fSTero Kristo prcm_irq_setup->suspended = true; 21891285b6fSTero Kristo } 21991285b6fSTero Kristo 22091285b6fSTero Kristo void omap_prcm_irq_complete(void) 22191285b6fSTero Kristo { 22291285b6fSTero Kristo prcm_irq_setup->suspended = false; 22391285b6fSTero Kristo 22491285b6fSTero Kristo /* If we have not saved the masks, do not attempt to restore */ 22591285b6fSTero Kristo if (!prcm_irq_setup->suspend_save_flag) 22691285b6fSTero Kristo return; 22791285b6fSTero Kristo 22891285b6fSTero Kristo prcm_irq_setup->suspend_save_flag = false; 22991285b6fSTero Kristo 23091285b6fSTero Kristo /* 23191285b6fSTero Kristo * Re-enable all masked PRCM irq sources, this causes the PRCM 23291285b6fSTero Kristo * interrupt to fire immediately if the events were masked 23391285b6fSTero Kristo * previously in the chain handler 23491285b6fSTero Kristo */ 23591285b6fSTero Kristo prcm_irq_setup->restore_irqen(prcm_irq_setup->saved_mask); 23691285b6fSTero Kristo } 23791285b6fSTero Kristo 2380a84a91cSTero Kristo /** 2390a84a91cSTero Kristo * omap_prcm_register_chain_handler - initializes the prcm chained interrupt 2400a84a91cSTero Kristo * handler based on provided parameters 2410a84a91cSTero Kristo * @irq_setup: hardware data about the underlying PRM/PRCM 2420a84a91cSTero Kristo * 2430a84a91cSTero Kristo * Set up the PRCM chained interrupt handler on the PRCM IRQ. Sets up 2440a84a91cSTero Kristo * one generic IRQ chip per PRM interrupt status/enable register pair. 2450a84a91cSTero Kristo * Returns 0 upon success, -EINVAL if called twice or if invalid 2460a84a91cSTero Kristo * arguments are passed, or -ENOMEM on any other error. 2470a84a91cSTero Kristo */ 2480a84a91cSTero Kristo int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup) 2490a84a91cSTero Kristo { 250eeb3711bSPaul Walmsley int nr_regs; 2510a84a91cSTero Kristo u32 mask[OMAP_PRCM_MAX_NR_PENDING_REG]; 2520a84a91cSTero Kristo int offset, i; 2530a84a91cSTero Kristo struct irq_chip_generic *gc; 2540a84a91cSTero Kristo struct irq_chip_type *ct; 2550a84a91cSTero Kristo 2560a84a91cSTero Kristo if (!irq_setup) 2570a84a91cSTero Kristo return -EINVAL; 2580a84a91cSTero Kristo 259eeb3711bSPaul Walmsley nr_regs = irq_setup->nr_regs; 260eeb3711bSPaul Walmsley 2610a84a91cSTero Kristo if (prcm_irq_setup) { 2620a84a91cSTero Kristo pr_err("PRCM: already initialized; won't reinitialize\n"); 2630a84a91cSTero Kristo return -EINVAL; 2640a84a91cSTero Kristo } 2650a84a91cSTero Kristo 2660a84a91cSTero Kristo if (nr_regs > OMAP_PRCM_MAX_NR_PENDING_REG) { 2670a84a91cSTero Kristo pr_err("PRCM: nr_regs too large\n"); 2680a84a91cSTero Kristo return -EINVAL; 2690a84a91cSTero Kristo } 2700a84a91cSTero Kristo 2710a84a91cSTero Kristo prcm_irq_setup = irq_setup; 2720a84a91cSTero Kristo 2730a84a91cSTero Kristo prcm_irq_chips = kzalloc(sizeof(void *) * nr_regs, GFP_KERNEL); 27491285b6fSTero Kristo prcm_irq_setup->saved_mask = kzalloc(sizeof(u32) * nr_regs, GFP_KERNEL); 2750a84a91cSTero Kristo prcm_irq_setup->priority_mask = kzalloc(sizeof(u32) * nr_regs, 2760a84a91cSTero Kristo GFP_KERNEL); 2770a84a91cSTero Kristo 27891285b6fSTero Kristo if (!prcm_irq_chips || !prcm_irq_setup->saved_mask || 27991285b6fSTero Kristo !prcm_irq_setup->priority_mask) { 2800a84a91cSTero Kristo pr_err("PRCM: kzalloc failed\n"); 2810a84a91cSTero Kristo goto err; 2820a84a91cSTero Kristo } 2830a84a91cSTero Kristo 2840a84a91cSTero Kristo memset(mask, 0, sizeof(mask)); 2850a84a91cSTero Kristo 2860a84a91cSTero Kristo for (i = 0; i < irq_setup->nr_irqs; i++) { 2870a84a91cSTero Kristo offset = irq_setup->irqs[i].offset; 2880a84a91cSTero Kristo mask[offset >> 5] |= 1 << (offset & 0x1f); 2890a84a91cSTero Kristo if (irq_setup->irqs[i].priority) 2900a84a91cSTero Kristo irq_setup->priority_mask[offset >> 5] |= 2910a84a91cSTero Kristo 1 << (offset & 0x1f); 2920a84a91cSTero Kristo } 2930a84a91cSTero Kristo 2940a84a91cSTero Kristo irq_set_chained_handler(irq_setup->irq, omap_prcm_irq_handler); 2950a84a91cSTero Kristo 2960a84a91cSTero Kristo irq_setup->base_irq = irq_alloc_descs(-1, 0, irq_setup->nr_regs * 32, 2970a84a91cSTero Kristo 0); 2980a84a91cSTero Kristo 2990a84a91cSTero Kristo if (irq_setup->base_irq < 0) { 3000a84a91cSTero Kristo pr_err("PRCM: failed to allocate irq descs: %d\n", 3010a84a91cSTero Kristo irq_setup->base_irq); 3020a84a91cSTero Kristo goto err; 3030a84a91cSTero Kristo } 3040a84a91cSTero Kristo 3054ba7c3c3SMing Lei for (i = 0; i < irq_setup->nr_regs; i++) { 3060a84a91cSTero Kristo gc = irq_alloc_generic_chip("PRCM", 1, 3070a84a91cSTero Kristo irq_setup->base_irq + i * 32, prm_base, 3080a84a91cSTero Kristo handle_level_irq); 3090a84a91cSTero Kristo 3100a84a91cSTero Kristo if (!gc) { 3110a84a91cSTero Kristo pr_err("PRCM: failed to allocate generic chip\n"); 3120a84a91cSTero Kristo goto err; 3130a84a91cSTero Kristo } 3140a84a91cSTero Kristo ct = gc->chip_types; 3150a84a91cSTero Kristo ct->chip.irq_ack = irq_gc_ack_set_bit; 3160a84a91cSTero Kristo ct->chip.irq_mask = irq_gc_mask_clr_bit; 3170a84a91cSTero Kristo ct->chip.irq_unmask = irq_gc_mask_set_bit; 3180a84a91cSTero Kristo 3190a84a91cSTero Kristo ct->regs.ack = irq_setup->ack + i * 4; 3200a84a91cSTero Kristo ct->regs.mask = irq_setup->mask + i * 4; 3210a84a91cSTero Kristo 3220a84a91cSTero Kristo irq_setup_generic_chip(gc, mask[i], 0, IRQ_NOREQUEST, 0); 3230a84a91cSTero Kristo prcm_irq_chips[i] = gc; 3240a84a91cSTero Kristo } 3250a84a91cSTero Kristo 326*30a69ef7STony Lindgren if (of_have_populated_dt()) { 327*30a69ef7STony Lindgren int irq = omap_prcm_event_to_irq("io"); 328*30a69ef7STony Lindgren if (cpu_is_omap34xx()) 329*30a69ef7STony Lindgren omap_pcs_legacy_init(irq, 330*30a69ef7STony Lindgren omap3xxx_prm_reconfigure_io_chain); 331*30a69ef7STony Lindgren else 332*30a69ef7STony Lindgren omap_pcs_legacy_init(irq, 333*30a69ef7STony Lindgren omap44xx_prm_reconfigure_io_chain); 334*30a69ef7STony Lindgren } 335*30a69ef7STony Lindgren 3360a84a91cSTero Kristo return 0; 3370a84a91cSTero Kristo 3380a84a91cSTero Kristo err: 3390a84a91cSTero Kristo omap_prcm_irq_cleanup(); 3400a84a91cSTero Kristo return -ENOMEM; 3410a84a91cSTero Kristo } 3423f4990f4SR Sricharan 343e24c3573SPaul Walmsley /** 344d9a16f9aSPaul Walmsley * omap2_set_globals_prm - set the PRM base address (for early use) 345d9a16f9aSPaul Walmsley * @prm: PRM base virtual address 346d9a16f9aSPaul Walmsley * 347d9a16f9aSPaul Walmsley * XXX Will be replaced when the PRM/CM drivers are completed. 3483f4990f4SR Sricharan */ 349d9a16f9aSPaul Walmsley void __init omap2_set_globals_prm(void __iomem *prm) 3503f4990f4SR Sricharan { 351d9a16f9aSPaul Walmsley prm_base = prm; 352d9a16f9aSPaul Walmsley } 353d9a16f9aSPaul Walmsley 354d9a16f9aSPaul Walmsley /** 3552bb2a5d3SPaul Walmsley * prm_read_reset_sources - return the sources of the SoC's last reset 3562bb2a5d3SPaul Walmsley * 3572bb2a5d3SPaul Walmsley * Return a u32 bitmask representing the reset sources that caused the 3582bb2a5d3SPaul Walmsley * SoC to reset. The low-level per-SoC functions called by this 3592bb2a5d3SPaul Walmsley * function remap the SoC-specific reset source bits into an 3602bb2a5d3SPaul Walmsley * OMAP-common set of reset source bits, defined in 3612bb2a5d3SPaul Walmsley * arch/arm/mach-omap2/prm.h. Returns the standardized reset source 3622bb2a5d3SPaul Walmsley * u32 bitmask from the hardware upon success, or returns (1 << 3632bb2a5d3SPaul Walmsley * OMAP_UNKNOWN_RST_SRC_ID_SHIFT) if no low-level read_reset_sources() 3642bb2a5d3SPaul Walmsley * function was registered. 3653f4990f4SR Sricharan */ 3662bb2a5d3SPaul Walmsley u32 prm_read_reset_sources(void) 3673f4990f4SR Sricharan { 3682bb2a5d3SPaul Walmsley u32 ret = 1 << OMAP_UNKNOWN_RST_SRC_ID_SHIFT; 3692bb2a5d3SPaul Walmsley 3702bb2a5d3SPaul Walmsley if (prm_ll_data->read_reset_sources) 3712bb2a5d3SPaul Walmsley ret = prm_ll_data->read_reset_sources(); 3722bb2a5d3SPaul Walmsley else 3732bb2a5d3SPaul Walmsley WARN_ONCE(1, "prm: %s: no mapping function defined for reset sources\n", __func__); 3742bb2a5d3SPaul Walmsley 3752bb2a5d3SPaul Walmsley return ret; 3762bb2a5d3SPaul Walmsley } 3772bb2a5d3SPaul Walmsley 3782bb2a5d3SPaul Walmsley /** 379e6d3a8b0SRajendra Nayak * prm_was_any_context_lost_old - was device context lost? (old API) 380e6d3a8b0SRajendra Nayak * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION) 381e6d3a8b0SRajendra Nayak * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST) 382e6d3a8b0SRajendra Nayak * @idx: CONTEXT register offset 383e6d3a8b0SRajendra Nayak * 384e6d3a8b0SRajendra Nayak * Return 1 if any bits were set in the *_CONTEXT_* register 385e6d3a8b0SRajendra Nayak * identified by (@part, @inst, @idx), which means that some context 386e6d3a8b0SRajendra Nayak * was lost for that module; otherwise, return 0. XXX Deprecated; 387e6d3a8b0SRajendra Nayak * callers need to use a less-SoC-dependent way to identify hardware 388e6d3a8b0SRajendra Nayak * IP blocks. 389e6d3a8b0SRajendra Nayak */ 390e6d3a8b0SRajendra Nayak bool prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx) 391e6d3a8b0SRajendra Nayak { 392e6d3a8b0SRajendra Nayak bool ret = true; 393e6d3a8b0SRajendra Nayak 394e6d3a8b0SRajendra Nayak if (prm_ll_data->was_any_context_lost_old) 395e6d3a8b0SRajendra Nayak ret = prm_ll_data->was_any_context_lost_old(part, inst, idx); 396e6d3a8b0SRajendra Nayak else 397e6d3a8b0SRajendra Nayak WARN_ONCE(1, "prm: %s: no mapping function defined\n", 398e6d3a8b0SRajendra Nayak __func__); 399e6d3a8b0SRajendra Nayak 400e6d3a8b0SRajendra Nayak return ret; 401e6d3a8b0SRajendra Nayak } 402e6d3a8b0SRajendra Nayak 403e6d3a8b0SRajendra Nayak /** 404e6d3a8b0SRajendra Nayak * prm_clear_context_lost_flags_old - clear context loss flags (old API) 405e6d3a8b0SRajendra Nayak * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION) 406e6d3a8b0SRajendra Nayak * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST) 407e6d3a8b0SRajendra Nayak * @idx: CONTEXT register offset 408e6d3a8b0SRajendra Nayak * 409e6d3a8b0SRajendra Nayak * Clear hardware context loss bits for the module identified by 410e6d3a8b0SRajendra Nayak * (@part, @inst, @idx). No return value. XXX Deprecated; callers 411e6d3a8b0SRajendra Nayak * need to use a less-SoC-dependent way to identify hardware IP 412e6d3a8b0SRajendra Nayak * blocks. 413e6d3a8b0SRajendra Nayak */ 414e6d3a8b0SRajendra Nayak void prm_clear_context_loss_flags_old(u8 part, s16 inst, u16 idx) 415e6d3a8b0SRajendra Nayak { 416e6d3a8b0SRajendra Nayak if (prm_ll_data->clear_context_loss_flags_old) 417e6d3a8b0SRajendra Nayak prm_ll_data->clear_context_loss_flags_old(part, inst, idx); 418e6d3a8b0SRajendra Nayak else 419e6d3a8b0SRajendra Nayak WARN_ONCE(1, "prm: %s: no mapping function defined\n", 420e6d3a8b0SRajendra Nayak __func__); 421e6d3a8b0SRajendra Nayak } 422e6d3a8b0SRajendra Nayak 423e6d3a8b0SRajendra Nayak /** 424e24c3573SPaul Walmsley * prm_register - register per-SoC low-level data with the PRM 425e24c3573SPaul Walmsley * @pld: low-level per-SoC OMAP PRM data & function pointers to register 426e24c3573SPaul Walmsley * 427e24c3573SPaul Walmsley * Register per-SoC low-level OMAP PRM data and function pointers with 428e24c3573SPaul Walmsley * the OMAP PRM common interface. The caller must keep the data 429e24c3573SPaul Walmsley * pointed to by @pld valid until it calls prm_unregister() and 430e24c3573SPaul Walmsley * it returns successfully. Returns 0 upon success, -EINVAL if @pld 431e24c3573SPaul Walmsley * is NULL, or -EEXIST if prm_register() has already been called 432e24c3573SPaul Walmsley * without an intervening prm_unregister(). 433e24c3573SPaul Walmsley */ 434e24c3573SPaul Walmsley int prm_register(struct prm_ll_data *pld) 435e24c3573SPaul Walmsley { 436e24c3573SPaul Walmsley if (!pld) 437e24c3573SPaul Walmsley return -EINVAL; 438e24c3573SPaul Walmsley 439e24c3573SPaul Walmsley if (prm_ll_data != &null_prm_ll_data) 440e24c3573SPaul Walmsley return -EEXIST; 441e24c3573SPaul Walmsley 442e24c3573SPaul Walmsley prm_ll_data = pld; 443e24c3573SPaul Walmsley 4443f4990f4SR Sricharan return 0; 4453f4990f4SR Sricharan } 4463f4990f4SR Sricharan 447e24c3573SPaul Walmsley /** 448e24c3573SPaul Walmsley * prm_unregister - unregister per-SoC low-level data & function pointers 449e24c3573SPaul Walmsley * @pld: low-level per-SoC OMAP PRM data & function pointers to unregister 450e24c3573SPaul Walmsley * 451e24c3573SPaul Walmsley * Unregister per-SoC low-level OMAP PRM data and function pointers 452e24c3573SPaul Walmsley * that were previously registered with prm_register(). The 453e24c3573SPaul Walmsley * caller may not destroy any of the data pointed to by @pld until 454e24c3573SPaul Walmsley * this function returns successfully. Returns 0 upon success, or 455e24c3573SPaul Walmsley * -EINVAL if @pld is NULL or if @pld does not match the struct 456e24c3573SPaul Walmsley * prm_ll_data * previously registered by prm_register(). 457e24c3573SPaul Walmsley */ 458e24c3573SPaul Walmsley int prm_unregister(struct prm_ll_data *pld) 4593f4990f4SR Sricharan { 460e24c3573SPaul Walmsley if (!pld || prm_ll_data != pld) 461e24c3573SPaul Walmsley return -EINVAL; 4623f4990f4SR Sricharan 463e24c3573SPaul Walmsley prm_ll_data = &null_prm_ll_data; 464e24c3573SPaul Walmsley 4653f4990f4SR Sricharan return 0; 4663f4990f4SR Sricharan } 467