Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Power and Sleep Controller (PSC) functions. |
| 3 | * |
| 4 | * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net> |
| 5 | * Copyright (C) 2008 Lyrtech <www.lyrtech.com> |
| 6 | * Copyright (C) 2004 Texas Instruments. |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <asm/arch/hardware.h> |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 28 | #include <asm/io.h> |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 29 | |
| 30 | /* |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 31 | * The PSC manages three inputs to a "module" which may be a peripheral or |
| 32 | * CPU. Those inputs are the module's: clock; reset signal; and sometimes |
| 33 | * its power domain. For our purposes, we only care whether clock and power |
| 34 | * are active, and the module is out of reset. |
| 35 | * |
| 36 | * DaVinci chips may include two separate power domains: "Always On" and "DSP". |
| 37 | * Chips without a DSP generally have only one domain. |
| 38 | * |
| 39 | * The "Always On" power domain is always on when the chip is on, and is |
| 40 | * powered by the VDD pins (on DM644X). The majority of DaVinci modules |
| 41 | * lie within the "Always On" power domain. |
| 42 | * |
| 43 | * A separate domain called the "DSP" domain houses the C64x+ and other video |
| 44 | * hardware such as VICP. In some chips, the "DSP" domain is not always on. |
| 45 | * The "DSP" power domain is powered by the CVDDDSP pins (on DM644X). |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 46 | */ |
| 47 | |
| 48 | /* Works on Always On power domain only (no PD argument) */ |
| 49 | void lpsc_on(unsigned int id) |
| 50 | { |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 51 | dv_reg_p mdstat, mdctl, ptstat, ptcmd; |
| 52 | #ifdef CONFIG_SOC_DA8XX |
| 53 | struct davinci_psc_regs *psc_regs; |
| 54 | #endif |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 55 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 56 | #ifndef CONFIG_SOC_DA8XX |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 57 | if (id >= DAVINCI_LPSC_GEM) |
| 58 | return; /* Don't work on DSP Power Domain */ |
| 59 | |
| 60 | mdstat = REG_P(PSC_MDSTAT_BASE + (id * 4)); |
| 61 | mdctl = REG_P(PSC_MDCTL_BASE + (id * 4)); |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 62 | ptstat = REG_P(PSC_PTSTAT); |
| 63 | ptcmd = REG_P(PSC_PTCMD); |
| 64 | #else |
| 65 | if (id < DAVINCI_LPSC_PSC1_BASE) { |
| 66 | if (id >= PSC_PSC0_MODULE_ID_CNT) |
| 67 | return; |
| 68 | psc_regs = davinci_psc0_regs; |
| 69 | mdstat = &psc_regs->psc0.mdstat[id]; |
| 70 | mdctl = &psc_regs->psc0.mdctl[id]; |
| 71 | } else { |
| 72 | id -= DAVINCI_LPSC_PSC1_BASE; |
| 73 | if (id >= PSC_PSC1_MODULE_ID_CNT) |
| 74 | return; |
| 75 | psc_regs = davinci_psc1_regs; |
| 76 | mdstat = &psc_regs->psc1.mdstat[id]; |
| 77 | mdctl = &psc_regs->psc1.mdctl[id]; |
| 78 | } |
| 79 | ptstat = &psc_regs->ptstat; |
| 80 | ptcmd = &psc_regs->ptcmd; |
| 81 | #endif |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 82 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 83 | while (readl(ptstat) & 0x01) |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 84 | continue; |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 85 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 86 | if ((readl(mdstat) & 0x1f) == 0x03) |
| 87 | return; /* Already on and enabled */ |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 88 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 89 | writel(readl(mdctl) | 0x03, mdctl); |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 90 | |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 91 | switch (id) { |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 92 | #ifdef CONFIG_SOC_DM644X |
| 93 | /* Special treatment for some modules as for sprue14 p.7.4.2 */ |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 94 | case DAVINCI_LPSC_VPSSSLV: |
| 95 | case DAVINCI_LPSC_EMAC: |
| 96 | case DAVINCI_LPSC_EMAC_WRAPPER: |
| 97 | case DAVINCI_LPSC_MDIO: |
| 98 | case DAVINCI_LPSC_USB: |
| 99 | case DAVINCI_LPSC_ATA: |
| 100 | case DAVINCI_LPSC_VLYNQ: |
| 101 | case DAVINCI_LPSC_UHPI: |
| 102 | case DAVINCI_LPSC_DDR_EMIF: |
| 103 | case DAVINCI_LPSC_AEMIF: |
| 104 | case DAVINCI_LPSC_MMC_SD: |
| 105 | case DAVINCI_LPSC_MEMSTICK: |
| 106 | case DAVINCI_LPSC_McBSP: |
| 107 | case DAVINCI_LPSC_GPIO: |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 108 | writel(readl(mdctl) | 0x200, mdctl); |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 109 | break; |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 110 | #endif |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 113 | writel(0x01, ptcmd); |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 114 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 115 | while (readl(ptstat) & 0x01) |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 116 | continue; |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 117 | while ((readl(mdstat) & 0x1f) != 0x03) |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 118 | continue; |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 119 | } |
| 120 | |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 121 | /* Not all DaVinci chips have a DSP power domain. */ |
| 122 | #ifdef CONFIG_SOC_DM644X |
| 123 | |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 124 | /* If DSPLINK is used, we don't want U-Boot to power on the DSP. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | #if !defined(CONFIG_SYS_USE_DSPLINK) |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 126 | void dsp_on(void) |
| 127 | { |
| 128 | int i; |
| 129 | |
| 130 | if (REG(PSC_PDSTAT1) & 0x1f) |
| 131 | return; /* Already on */ |
| 132 | |
| 133 | REG(PSC_GBLCTL) |= 0x01; |
| 134 | REG(PSC_PDCTL1) |= 0x01; |
| 135 | REG(PSC_PDCTL1) &= ~0x100; |
| 136 | REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) |= 0x03; |
| 137 | REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) &= 0xfffffeff; |
| 138 | REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) |= 0x03; |
| 139 | REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) &= 0xfffffeff; |
| 140 | REG(PSC_PTCMD) = 0x02; |
| 141 | |
| 142 | for (i = 0; i < 100; i++) { |
| 143 | if (REG(PSC_EPCPR) & 0x02) |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | REG(PSC_CHP_SHRTSW) = 0x01; |
| 148 | REG(PSC_PDCTL1) |= 0x100; |
| 149 | REG(PSC_EPCCR) = 0x02; |
| 150 | |
| 151 | for (i = 0; i < 100; i++) { |
| 152 | if (!(REG(PSC_PTSTAT) & 0x02)) |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | REG(PSC_GBLCTL) &= ~0x1f; |
| 157 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 158 | #endif /* CONFIG_SYS_USE_DSPLINK */ |
Hugo Villeneuve | c9a2137 | 2008-11-21 14:35:56 -0500 | [diff] [blame] | 159 | |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 160 | #endif /* have a DSP */ |