]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/u8500/cpu.c
u8500: Enabling power to MMC device on AB8500 V2
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / u8500 / cpu.c
1 /*
2  * Copyright (C) 2012 Linaro Limited
3  * Mathieu Poirier <mathieu.poirier@linaro.org>
4  *
5  * Based on original code from Joakim Axelsson at ST-Ericsson
6  * (C) Copyright 2010 ST-Ericsson
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
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (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., 59 Temple Place, Suite 330, Boston,
24  * MA 02111-1307 USA
25  */
26
27 #include <common.h>
28 #include <asm/io.h>
29 #include <asm/arch/prcmu.h>
30 #include <asm/arch/clock.h>
31 #include <asm/arch/hardware.h>
32
33 #include <asm/arch/hardware.h>
34
35 #define CPUID_DB8500V1          0x411fc091
36 #define CPUID_DB8500V2          0x412fc091
37 #define ASICID_DB8500V11        0x008500A1
38
39 static unsigned int read_asicid(void);
40
41 static inline unsigned int read_cpuid(void)
42 {
43         unsigned int val;
44
45         /* Main ID register (MIDR) */
46         asm("mrc        p15, 0, %0, c0, c0, 0"
47            : "=r" (val)
48            :
49            : "cc");
50
51         return val;
52 }
53
54 static int cpu_is_u8500v11(void)
55 {
56         return read_asicid() == ASICID_DB8500V11;
57 }
58
59 static int cpu_is_u8500v2(void)
60 {
61         return read_cpuid() == CPUID_DB8500V2;
62 }
63
64 static unsigned int read_asicid(void)
65 {
66         unsigned int *address;
67
68         if (cpu_is_u8500v2())
69                 address = (void *) U8500_ASIC_ID_LOC_V2;
70         else
71                 address = (void *) U8500_ASIC_ID_LOC_ED_V1;
72
73         return readl(address);
74 }
75
76 #ifdef CONFIG_ARCH_CPU_INIT
77 /*
78  * SOC specific cpu init
79  */
80 int arch_cpu_init(void)
81 {
82         db8500_prcmu_init();
83         db8500_clocks_init();
84
85         return 0;
86 }
87 #endif /* CONFIG_ARCH_CPU_INIT */
88
89 #ifdef CONFIG_MMC
90
91 int u8500_mmc_power_init(void)
92 {
93         int ret;
94         int enable, voltage;
95         int ab8500_revision;
96
97         if (!cpu_is_u8500v11() && !cpu_is_u8500v2())
98                 return 0;
99
100         /* Get AB8500 revision */
101         ret = ab8500_read(AB8500_MISC, AB8500_REV_REG);
102         if (ret < 0)
103                 goto out;
104
105         ab8500_revision = ret;
106
107         /*
108          * On v1.1 HREF boards (HREF+), Vaux3 needs to be enabled for the SD
109          * card to work.  This is done by enabling the regulators in the AB8500
110          * via PRCMU I2C transactions.
111          *
112          * This code is derived from the handling of AB8500_LDO_VAUX3 in
113          * ab8500_ldo_enable() and ab8500_ldo_disable() in Linux.
114          *
115          * Turn off and delay is required to have it work across soft reboots.
116          */
117
118         /* Turn off (read-modify-write) */
119         ret = ab8500_read(AB8500_REGU_CTRL2,
120                                 AB8500_REGU_VRF1VAUX3_REGU_REG);
121         if (ret < 0)
122                 goto out;
123
124         enable = ret;
125
126         /* Turn off */
127         ret = ab8500_write(AB8500_REGU_CTRL2,
128                         AB8500_REGU_VRF1VAUX3_REGU_REG,
129                         enable & ~LDO_VAUX3_ENABLE_MASK);
130         if (ret < 0)
131                 goto out;
132
133         udelay(10 * 1000);
134
135         /* Set the voltage to 2.91 V or 2.9 V without overriding VRF1 value */
136         ret = ab8500_read(AB8500_REGU_CTRL2,
137                         AB8500_REGU_VRF1VAUX3_SEL_REG);
138         if (ret < 0)
139                 goto out;
140
141         voltage = ret;
142
143         if (ab8500_revision < 0x20) {
144                 voltage &= ~LDO_VAUX3_SEL_MASK;
145                 voltage |= LDO_VAUX3_SEL_2V9;
146         } else {
147                 voltage &= ~LDO_VAUX3_V2_SEL_MASK;
148                 voltage |= LDO_VAUX3_V2_SEL_2V91;
149         }
150
151         ret = ab8500_write(AB8500_REGU_CTRL2,
152                         AB8500_REGU_VRF1VAUX3_SEL_REG, voltage);
153         if (ret < 0)
154                 goto out;
155
156         /* Turn on the supply */
157         enable &= ~LDO_VAUX3_ENABLE_MASK;
158         enable |= LDO_VAUX3_ENABLE_VAL;
159
160         ret = ab8500_write(AB8500_REGU_CTRL2,
161                         AB8500_REGU_VRF1VAUX3_REGU_REG, enable);
162
163 out:
164         return ret;
165 }
166 #endif /* CONFIG_MMC */