1cf21405fSPaul Walmsley /* 2cf21405fSPaul Walmsley * OMAP2/3 PRM module functions 3cf21405fSPaul Walmsley * 426c98c56SPaul Walmsley * Copyright (C) 2010-2011 Texas Instruments, Inc. 5cf21405fSPaul Walmsley * Copyright (C) 2010 Nokia Corporation 6cf21405fSPaul Walmsley * Benoît Cousson 7cf21405fSPaul Walmsley * Paul Walmsley 8cf21405fSPaul Walmsley * 9cf21405fSPaul Walmsley * This program is free software; you can redistribute it and/or modify 10cf21405fSPaul Walmsley * it under the terms of the GNU General Public License version 2 as 11cf21405fSPaul Walmsley * published by the Free Software Foundation. 12cf21405fSPaul Walmsley */ 13cf21405fSPaul Walmsley 14cf21405fSPaul Walmsley #include <linux/kernel.h> 15cf21405fSPaul Walmsley #include <linux/errno.h> 16cf21405fSPaul Walmsley #include <linux/err.h> 1759fb659bSPaul Walmsley #include <linux/io.h> 18cf21405fSPaul Walmsley 19dbc04161STony Lindgren #include "common.h" 2049815399SPaul Walmsley #include "powerdomain.h" 2159fb659bSPaul Walmsley #include "prm2xxx_3xxx.h" 22cf21405fSPaul Walmsley #include "prm-regbits-24xx.h" 234bd5259eSPaul Walmsley #include "clockdomain.h" 2459fb659bSPaul Walmsley 25cf21405fSPaul Walmsley /** 26cf21405fSPaul Walmsley * omap2_prm_is_hardreset_asserted - read the HW reset line state of 27cf21405fSPaul Walmsley * submodules contained in the hwmod module 28cf21405fSPaul Walmsley * @prm_mod: PRM submodule base (e.g. CORE_MOD) 29cf21405fSPaul Walmsley * @shift: register bit shift corresponding to the reset line to check 30cf21405fSPaul Walmsley * 31cf21405fSPaul Walmsley * Returns 1 if the (sub)module hardreset line is currently asserted, 32cf21405fSPaul Walmsley * 0 if the (sub)module hardreset line is not currently asserted, or 33cf21405fSPaul Walmsley * -EINVAL if called while running on a non-OMAP2/3 chip. 34cf21405fSPaul Walmsley */ 35cf21405fSPaul Walmsley int omap2_prm_is_hardreset_asserted(s16 prm_mod, u8 shift) 36cf21405fSPaul Walmsley { 37c4d7e58fSPaul Walmsley return omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, 38cf21405fSPaul Walmsley (1 << shift)); 39cf21405fSPaul Walmsley } 40cf21405fSPaul Walmsley 41cf21405fSPaul Walmsley /** 42cf21405fSPaul Walmsley * omap2_prm_assert_hardreset - assert the HW reset line of a submodule 43cf21405fSPaul Walmsley * @prm_mod: PRM submodule base (e.g. CORE_MOD) 44cf21405fSPaul Walmsley * @shift: register bit shift corresponding to the reset line to assert 45cf21405fSPaul Walmsley * 46cf21405fSPaul Walmsley * Some IPs like dsp or iva contain processors that require an HW 47cf21405fSPaul Walmsley * reset line to be asserted / deasserted in order to fully enable the 48cf21405fSPaul Walmsley * IP. These modules may have multiple hard-reset lines that reset 49cf21405fSPaul Walmsley * different 'submodules' inside the IP block. This function will 50cf21405fSPaul Walmsley * place the submodule into reset. Returns 0 upon success or -EINVAL 51cf21405fSPaul Walmsley * upon an argument error. 52cf21405fSPaul Walmsley */ 53cf21405fSPaul Walmsley int omap2_prm_assert_hardreset(s16 prm_mod, u8 shift) 54cf21405fSPaul Walmsley { 55cf21405fSPaul Walmsley u32 mask; 56cf21405fSPaul Walmsley 57cf21405fSPaul Walmsley mask = 1 << shift; 58c4d7e58fSPaul Walmsley omap2_prm_rmw_mod_reg_bits(mask, mask, prm_mod, OMAP2_RM_RSTCTRL); 59cf21405fSPaul Walmsley 60cf21405fSPaul Walmsley return 0; 61cf21405fSPaul Walmsley } 62cf21405fSPaul Walmsley 63cf21405fSPaul Walmsley /** 64cf21405fSPaul Walmsley * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait 65cf21405fSPaul Walmsley * @prm_mod: PRM submodule base (e.g. CORE_MOD) 66cc1226e7Somar ramirez * @rst_shift: register bit shift corresponding to the reset line to deassert 67cc1226e7Somar ramirez * @st_shift: register bit shift for the status of the deasserted submodule 68cf21405fSPaul Walmsley * 69cf21405fSPaul Walmsley * Some IPs like dsp or iva contain processors that require an HW 70cf21405fSPaul Walmsley * reset line to be asserted / deasserted in order to fully enable the 71cf21405fSPaul Walmsley * IP. These modules may have multiple hard-reset lines that reset 72cf21405fSPaul Walmsley * different 'submodules' inside the IP block. This function will 73cf21405fSPaul Walmsley * take the submodule out of reset and wait until the PRCM indicates 74cf21405fSPaul Walmsley * that the reset has completed before returning. Returns 0 upon success or 75cf21405fSPaul Walmsley * -EINVAL upon an argument error, -EEXIST if the submodule was already out 76cf21405fSPaul Walmsley * of reset, or -EBUSY if the submodule did not exit reset promptly. 77cf21405fSPaul Walmsley */ 78cc1226e7Somar ramirez int omap2_prm_deassert_hardreset(s16 prm_mod, u8 rst_shift, u8 st_shift) 79cf21405fSPaul Walmsley { 80cc1226e7Somar ramirez u32 rst, st; 81cf21405fSPaul Walmsley int c; 82cf21405fSPaul Walmsley 83cc1226e7Somar ramirez rst = 1 << rst_shift; 84cc1226e7Somar ramirez st = 1 << st_shift; 85cf21405fSPaul Walmsley 86cf21405fSPaul Walmsley /* Check the current status to avoid de-asserting the line twice */ 87cc1226e7Somar ramirez if (omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, rst) == 0) 88cf21405fSPaul Walmsley return -EEXIST; 89cf21405fSPaul Walmsley 90cf21405fSPaul Walmsley /* Clear the reset status by writing 1 to the status bit */ 91cc1226e7Somar ramirez omap2_prm_rmw_mod_reg_bits(0xffffffff, st, prm_mod, OMAP2_RM_RSTST); 92cf21405fSPaul Walmsley /* de-assert the reset control line */ 93cc1226e7Somar ramirez omap2_prm_rmw_mod_reg_bits(rst, 0, prm_mod, OMAP2_RM_RSTCTRL); 94cf21405fSPaul Walmsley /* wait the status to be set */ 95c4d7e58fSPaul Walmsley omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST, 96cc1226e7Somar ramirez st), 97cf21405fSPaul Walmsley MAX_MODULE_HARDRESET_WAIT, c); 98cf21405fSPaul Walmsley 99cf21405fSPaul Walmsley return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0; 100cf21405fSPaul Walmsley } 10158aaa599SKevin Hilman 10249815399SPaul Walmsley 10349815399SPaul Walmsley /* Powerdomain low-level functions */ 10449815399SPaul Walmsley 10549815399SPaul Walmsley /* Common functions across OMAP2 and OMAP3 */ 10649815399SPaul Walmsley int omap2_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, 10749815399SPaul Walmsley u8 pwrst) 10849815399SPaul Walmsley { 10949815399SPaul Walmsley u32 m; 11049815399SPaul Walmsley 11149815399SPaul Walmsley m = omap2_pwrdm_get_mem_bank_onstate_mask(bank); 11249815399SPaul Walmsley 11349815399SPaul Walmsley omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs, 11449815399SPaul Walmsley OMAP2_PM_PWSTCTRL); 11549815399SPaul Walmsley 11649815399SPaul Walmsley return 0; 11749815399SPaul Walmsley } 11849815399SPaul Walmsley 11949815399SPaul Walmsley int omap2_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, 12049815399SPaul Walmsley u8 pwrst) 12149815399SPaul Walmsley { 12249815399SPaul Walmsley u32 m; 12349815399SPaul Walmsley 12449815399SPaul Walmsley m = omap2_pwrdm_get_mem_bank_retst_mask(bank); 12549815399SPaul Walmsley 12649815399SPaul Walmsley omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs, 12749815399SPaul Walmsley OMAP2_PM_PWSTCTRL); 12849815399SPaul Walmsley 12949815399SPaul Walmsley return 0; 13049815399SPaul Walmsley } 13149815399SPaul Walmsley 13249815399SPaul Walmsley int omap2_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank) 13349815399SPaul Walmsley { 13449815399SPaul Walmsley u32 m; 13549815399SPaul Walmsley 13649815399SPaul Walmsley m = omap2_pwrdm_get_mem_bank_stst_mask(bank); 13749815399SPaul Walmsley 13849815399SPaul Walmsley return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP2_PM_PWSTST, 13949815399SPaul Walmsley m); 14049815399SPaul Walmsley } 14149815399SPaul Walmsley 14249815399SPaul Walmsley int omap2_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank) 14349815399SPaul Walmsley { 14449815399SPaul Walmsley u32 m; 14549815399SPaul Walmsley 14649815399SPaul Walmsley m = omap2_pwrdm_get_mem_bank_retst_mask(bank); 14749815399SPaul Walmsley 14849815399SPaul Walmsley return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, 14949815399SPaul Walmsley OMAP2_PM_PWSTCTRL, m); 15049815399SPaul Walmsley } 15149815399SPaul Walmsley 15249815399SPaul Walmsley int omap2_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst) 15349815399SPaul Walmsley { 15449815399SPaul Walmsley u32 v; 15549815399SPaul Walmsley 15649815399SPaul Walmsley v = pwrst << __ffs(OMAP_LOGICRETSTATE_MASK); 15749815399SPaul Walmsley omap2_prm_rmw_mod_reg_bits(OMAP_LOGICRETSTATE_MASK, v, pwrdm->prcm_offs, 15849815399SPaul Walmsley OMAP2_PM_PWSTCTRL); 15949815399SPaul Walmsley 16049815399SPaul Walmsley return 0; 16149815399SPaul Walmsley } 16249815399SPaul Walmsley 16349815399SPaul Walmsley int omap2_pwrdm_wait_transition(struct powerdomain *pwrdm) 16449815399SPaul Walmsley { 16549815399SPaul Walmsley u32 c = 0; 16649815399SPaul Walmsley 16749815399SPaul Walmsley /* 16849815399SPaul Walmsley * REVISIT: pwrdm_wait_transition() may be better implemented 16949815399SPaul Walmsley * via a callback and a periodic timer check -- how long do we expect 17049815399SPaul Walmsley * powerdomain transitions to take? 17149815399SPaul Walmsley */ 17249815399SPaul Walmsley 17349815399SPaul Walmsley /* XXX Is this udelay() value meaningful? */ 17449815399SPaul Walmsley while ((omap2_prm_read_mod_reg(pwrdm->prcm_offs, OMAP2_PM_PWSTST) & 17549815399SPaul Walmsley OMAP_INTRANSITION_MASK) && 17649815399SPaul Walmsley (c++ < PWRDM_TRANSITION_BAILOUT)) 17749815399SPaul Walmsley udelay(1); 17849815399SPaul Walmsley 17949815399SPaul Walmsley if (c > PWRDM_TRANSITION_BAILOUT) { 18049815399SPaul Walmsley pr_err("powerdomain: %s: waited too long to complete transition\n", 18149815399SPaul Walmsley pwrdm->name); 18249815399SPaul Walmsley return -EAGAIN; 18349815399SPaul Walmsley } 18449815399SPaul Walmsley 18549815399SPaul Walmsley pr_debug("powerdomain: completed transition in %d loops\n", c); 18649815399SPaul Walmsley 18749815399SPaul Walmsley return 0; 18849815399SPaul Walmsley } 18949815399SPaul Walmsley 1904bd5259eSPaul Walmsley int omap2_clkdm_add_wkdep(struct clockdomain *clkdm1, 1914bd5259eSPaul Walmsley struct clockdomain *clkdm2) 1924bd5259eSPaul Walmsley { 1934bd5259eSPaul Walmsley omap2_prm_set_mod_reg_bits((1 << clkdm2->dep_bit), 1944bd5259eSPaul Walmsley clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP); 1954bd5259eSPaul Walmsley return 0; 1964bd5259eSPaul Walmsley } 1974bd5259eSPaul Walmsley 1984bd5259eSPaul Walmsley int omap2_clkdm_del_wkdep(struct clockdomain *clkdm1, 1994bd5259eSPaul Walmsley struct clockdomain *clkdm2) 2004bd5259eSPaul Walmsley { 2014bd5259eSPaul Walmsley omap2_prm_clear_mod_reg_bits((1 << clkdm2->dep_bit), 2024bd5259eSPaul Walmsley clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP); 2034bd5259eSPaul Walmsley return 0; 2044bd5259eSPaul Walmsley } 2054bd5259eSPaul Walmsley 2064bd5259eSPaul Walmsley int omap2_clkdm_read_wkdep(struct clockdomain *clkdm1, 2074bd5259eSPaul Walmsley struct clockdomain *clkdm2) 2084bd5259eSPaul Walmsley { 2094bd5259eSPaul Walmsley return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs, 2104bd5259eSPaul Walmsley PM_WKDEP, (1 << clkdm2->dep_bit)); 2114bd5259eSPaul Walmsley } 2124bd5259eSPaul Walmsley 213*92493870SPaul Walmsley /* XXX Caller must hold the clkdm's powerdomain lock */ 2144bd5259eSPaul Walmsley int omap2_clkdm_clear_all_wkdeps(struct clockdomain *clkdm) 2154bd5259eSPaul Walmsley { 2164bd5259eSPaul Walmsley struct clkdm_dep *cd; 2174bd5259eSPaul Walmsley u32 mask = 0; 2184bd5259eSPaul Walmsley 2194bd5259eSPaul Walmsley for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) { 2204bd5259eSPaul Walmsley if (!cd->clkdm) 2214bd5259eSPaul Walmsley continue; /* only happens if data is erroneous */ 2224bd5259eSPaul Walmsley 2234bd5259eSPaul Walmsley /* PRM accesses are slow, so minimize them */ 2244bd5259eSPaul Walmsley mask |= 1 << cd->clkdm->dep_bit; 225*92493870SPaul Walmsley cd->wkdep_usecount = 0; 2264bd5259eSPaul Walmsley } 2274bd5259eSPaul Walmsley 2284bd5259eSPaul Walmsley omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs, 2294bd5259eSPaul Walmsley PM_WKDEP); 2304bd5259eSPaul Walmsley return 0; 2314bd5259eSPaul Walmsley } 2324bd5259eSPaul Walmsley 233