Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * TI DaVinci Power and Sleep Controller (PSC) |
| 3 | * |
| 4 | * Copyright (C) 2006 Texas Instruments. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | */ |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 24 | #include <linux/io.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 25 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 26 | #include <mach/hardware.h> |
| 27 | #include <mach/psc.h> |
| 28 | #include <mach/mux.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 29 | |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 30 | /* PSC register offsets */ |
| 31 | #define EPCPR 0x070 |
| 32 | #define PTCMD 0x120 |
| 33 | #define PTSTAT 0x128 |
| 34 | #define PDSTAT 0x200 |
| 35 | #define PDCTL1 0x304 |
| 36 | #define MDSTAT 0x800 |
| 37 | #define MDCTL 0xA00 |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 38 | |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 39 | /* System control register offsets */ |
| 40 | #define VDD3P3V_PWDN 0x48 |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 41 | |
| 42 | static void davinci_psc_mux(unsigned int id) |
| 43 | { |
| 44 | switch (id) { |
| 45 | case DAVINCI_LPSC_ATA: |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 46 | davinci_mux_peripheral(DAVINCI_MUX_HDIREN, 1); |
| 47 | davinci_mux_peripheral(DAVINCI_MUX_ATAEN, 1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 48 | break; |
| 49 | case DAVINCI_LPSC_MMC_SD: |
| 50 | /* VDD power manupulations are done in U-Boot for CPMAC |
| 51 | * so applies to MMC as well |
| 52 | */ |
| 53 | /*Set up the pull regiter for MMC */ |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 54 | davinci_writel(0, DAVINCI_SYSTEM_MODULE_BASE + VDD3P3V_PWDN); |
| 55 | davinci_mux_peripheral(DAVINCI_MUX_MSTK, 0); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 56 | break; |
| 57 | case DAVINCI_LPSC_I2C: |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 58 | davinci_mux_peripheral(DAVINCI_MUX_I2C, 1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 59 | break; |
| 60 | case DAVINCI_LPSC_McBSP: |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 61 | davinci_mux_peripheral(DAVINCI_MUX_ASP, 1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 62 | break; |
| 63 | default: |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /* Enable or disable a PSC domain */ |
| 69 | void davinci_psc_config(unsigned int domain, unsigned int id, char enable) |
| 70 | { |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 71 | u32 epcpr, ptcmd, ptstat, pdstat, pdctl1, mdstat, mdctl, mdstat_mask; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 72 | |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 73 | mdctl = davinci_readl(DAVINCI_PWR_SLEEP_CNTRL_BASE + MDCTL + 4 * id); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 74 | if (enable) |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 75 | mdctl |= 0x00000003; /* Enable Module */ |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 76 | else |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 77 | mdctl &= 0xFFFFFFF2; /* Disable Module */ |
| 78 | davinci_writel(mdctl, DAVINCI_PWR_SLEEP_CNTRL_BASE + MDCTL + 4 * id); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 79 | |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 80 | pdstat = davinci_readl(DAVINCI_PWR_SLEEP_CNTRL_BASE + PDSTAT); |
| 81 | if ((pdstat & 0x00000001) == 0) { |
| 82 | pdctl1 = davinci_readl(DAVINCI_PWR_SLEEP_CNTRL_BASE + PDCTL1); |
| 83 | pdctl1 |= 0x1; |
| 84 | davinci_writel(pdctl1, DAVINCI_PWR_SLEEP_CNTRL_BASE + PDCTL1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 85 | |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 86 | ptcmd = 1 << domain; |
| 87 | davinci_writel(ptcmd, DAVINCI_PWR_SLEEP_CNTRL_BASE + PTCMD); |
| 88 | |
| 89 | do { |
| 90 | epcpr = davinci_readl(DAVINCI_PWR_SLEEP_CNTRL_BASE + |
| 91 | EPCPR); |
| 92 | } while ((((epcpr >> domain) & 1) == 0)); |
| 93 | |
| 94 | pdctl1 = davinci_readl(DAVINCI_PWR_SLEEP_CNTRL_BASE + PDCTL1); |
| 95 | pdctl1 |= 0x100; |
| 96 | davinci_writel(pdctl1, DAVINCI_PWR_SLEEP_CNTRL_BASE + PDCTL1); |
| 97 | |
| 98 | do { |
| 99 | ptstat = davinci_readl(DAVINCI_PWR_SLEEP_CNTRL_BASE + |
| 100 | PTSTAT); |
| 101 | } while (!(((ptstat >> domain) & 1) == 0)); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 102 | } else { |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 103 | ptcmd = 1 << domain; |
| 104 | davinci_writel(ptcmd, DAVINCI_PWR_SLEEP_CNTRL_BASE + PTCMD); |
| 105 | |
| 106 | do { |
| 107 | ptstat = davinci_readl(DAVINCI_PWR_SLEEP_CNTRL_BASE + |
| 108 | PTSTAT); |
| 109 | } while (!(((ptstat >> domain) & 1) == 0)); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | if (enable) |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 113 | mdstat_mask = 0x3; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 114 | else |
Vladimir Barinov | 83f5322 | 2007-07-10 13:10:04 +0100 | [diff] [blame] | 115 | mdstat_mask = 0x2; |
| 116 | |
| 117 | do { |
| 118 | mdstat = davinci_readl(DAVINCI_PWR_SLEEP_CNTRL_BASE + |
| 119 | MDSTAT + 4 * id); |
| 120 | } while (!((mdstat & 0x0000001F) == mdstat_mask)); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 121 | |
| 122 | if (enable) |
| 123 | davinci_psc_mux(id); |
| 124 | } |
| 125 | |
| 126 | void __init davinci_psc_init(void) |
| 127 | { |
| 128 | davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_VPSSMSTR, 1); |
| 129 | davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_VPSSSLV, 1); |
| 130 | davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_TPCC, 1); |
| 131 | davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_TPTC0, 1); |
| 132 | davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_TPTC1, 1); |
| 133 | davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_GPIO, 1); |
| 134 | |
| 135 | /* Turn on WatchDog timer LPSC. Needed for RESET to work */ |
| 136 | davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_TIMER2, 1); |
| 137 | } |