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