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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <asm/arch/hardware.h> |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 13 | #include <asm/io.h> |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 14 | |
| 15 | /* |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 16 | * The PSC manages three inputs to a "module" which may be a peripheral or |
| 17 | * CPU. Those inputs are the module's: clock; reset signal; and sometimes |
| 18 | * its power domain. For our purposes, we only care whether clock and power |
| 19 | * are active, and the module is out of reset. |
| 20 | * |
| 21 | * DaVinci chips may include two separate power domains: "Always On" and "DSP". |
| 22 | * Chips without a DSP generally have only one domain. |
| 23 | * |
| 24 | * The "Always On" power domain is always on when the chip is on, and is |
| 25 | * powered by the VDD pins (on DM644X). The majority of DaVinci modules |
| 26 | * lie within the "Always On" power domain. |
| 27 | * |
| 28 | * A separate domain called the "DSP" domain houses the C64x+ and other video |
| 29 | * hardware such as VICP. In some chips, the "DSP" domain is not always on. |
| 30 | * The "DSP" power domain is powered by the CVDDDSP pins (on DM644X). |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | /* Works on Always On power domain only (no PD argument) */ |
Christian Riesch | a4cd16f | 2011-10-12 21:26:43 +0000 | [diff] [blame] | 34 | static void lpsc_transition(unsigned int id, unsigned int state) |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 35 | { |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 36 | dv_reg_p mdstat, mdctl, ptstat, ptcmd; |
| 37 | #ifdef CONFIG_SOC_DA8XX |
| 38 | struct davinci_psc_regs *psc_regs; |
| 39 | #endif |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 40 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 41 | #ifndef CONFIG_SOC_DA8XX |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 42 | if (id >= DAVINCI_LPSC_GEM) |
| 43 | return; /* Don't work on DSP Power Domain */ |
| 44 | |
| 45 | mdstat = REG_P(PSC_MDSTAT_BASE + (id * 4)); |
| 46 | mdctl = REG_P(PSC_MDCTL_BASE + (id * 4)); |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 47 | ptstat = REG_P(PSC_PTSTAT); |
| 48 | ptcmd = REG_P(PSC_PTCMD); |
| 49 | #else |
| 50 | if (id < DAVINCI_LPSC_PSC1_BASE) { |
| 51 | if (id >= PSC_PSC0_MODULE_ID_CNT) |
| 52 | return; |
| 53 | psc_regs = davinci_psc0_regs; |
| 54 | mdstat = &psc_regs->psc0.mdstat[id]; |
| 55 | mdctl = &psc_regs->psc0.mdctl[id]; |
| 56 | } else { |
| 57 | id -= DAVINCI_LPSC_PSC1_BASE; |
| 58 | if (id >= PSC_PSC1_MODULE_ID_CNT) |
| 59 | return; |
| 60 | psc_regs = davinci_psc1_regs; |
| 61 | mdstat = &psc_regs->psc1.mdstat[id]; |
| 62 | mdctl = &psc_regs->psc1.mdctl[id]; |
| 63 | } |
| 64 | ptstat = &psc_regs->ptstat; |
| 65 | ptcmd = &psc_regs->ptcmd; |
| 66 | #endif |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 67 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 68 | while (readl(ptstat) & 0x01) |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 69 | continue; |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 70 | |
Christian Riesch | a4cd16f | 2011-10-12 21:26:43 +0000 | [diff] [blame] | 71 | if ((readl(mdstat) & PSC_MDSTAT_STATE) == state) |
| 72 | return; /* Already in that state */ |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 73 | |
Christian Riesch | a4cd16f | 2011-10-12 21:26:43 +0000 | [diff] [blame] | 74 | writel((readl(mdctl) & ~PSC_MDCTL_NEXT) | state, mdctl); |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 75 | |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 76 | switch (id) { |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 77 | #ifdef CONFIG_SOC_DM644X |
| 78 | /* Special treatment for some modules as for sprue14 p.7.4.2 */ |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 79 | case DAVINCI_LPSC_VPSSSLV: |
| 80 | case DAVINCI_LPSC_EMAC: |
| 81 | case DAVINCI_LPSC_EMAC_WRAPPER: |
| 82 | case DAVINCI_LPSC_MDIO: |
| 83 | case DAVINCI_LPSC_USB: |
| 84 | case DAVINCI_LPSC_ATA: |
| 85 | case DAVINCI_LPSC_VLYNQ: |
| 86 | case DAVINCI_LPSC_UHPI: |
| 87 | case DAVINCI_LPSC_DDR_EMIF: |
| 88 | case DAVINCI_LPSC_AEMIF: |
| 89 | case DAVINCI_LPSC_MMC_SD: |
| 90 | case DAVINCI_LPSC_MEMSTICK: |
| 91 | case DAVINCI_LPSC_McBSP: |
| 92 | case DAVINCI_LPSC_GPIO: |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 93 | writel(readl(mdctl) | 0x200, mdctl); |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 94 | break; |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 95 | #endif |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 96 | } |
| 97 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 98 | writel(0x01, ptcmd); |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 99 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 100 | while (readl(ptstat) & 0x01) |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 101 | continue; |
Christian Riesch | a4cd16f | 2011-10-12 21:26:43 +0000 | [diff] [blame] | 102 | while ((readl(mdstat) & PSC_MDSTAT_STATE) != state) |
David Brownell | 5f02add | 2009-05-15 23:44:08 +0200 | [diff] [blame] | 103 | continue; |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Christian Riesch | a4cd16f | 2011-10-12 21:26:43 +0000 | [diff] [blame] | 106 | void lpsc_on(unsigned int id) |
| 107 | { |
| 108 | lpsc_transition(id, 0x03); |
| 109 | } |
| 110 | |
| 111 | void lpsc_syncreset(unsigned int id) |
| 112 | { |
| 113 | lpsc_transition(id, 0x01); |
| 114 | } |
| 115 | |
Sughosh Ganu | 282e2af | 2012-08-09 10:45:20 +0000 | [diff] [blame] | 116 | void lpsc_disable(unsigned int id) |
| 117 | { |
| 118 | lpsc_transition(id, 0x0); |
| 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 */ |