blob: 9a32924194c1310106b04e53f264853407080c47 [file] [log] [blame]
Shashank Mittal23b8f422010-04-16 19:27:21 -07001/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of Code Aurora Forum, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <string.h>
30#include <stdlib.h>
31#include <debug.h>
32#include <reg.h>
Shashank Mittal7afbf282010-06-02 19:48:31 -070033#include "mmc.h"
Shashank Mittal23b8f422010-04-16 19:27:21 -070034
35#define CLK_CTL_BASE 0x00900000
36
37#define SDC_NS(n) (CLK_CTL_BASE + 0x282C + 32*((n) - 1))
38#define SDC1_NS SDC_NS(1)
39#define SDC2_NS SDC_NS(2)
40#define SDC3_NS SDC_NS(3)
41#define SDC4_NS SDC_NS(4)
42#define SDC5_NS SDC_NS(5)
43
44#define SDC_MD(n) (CLK_CTL_BASE + 0x2828 + 32*((n) - 1))
45#define SDC1_MD SDC_MD(1)
46#define SDC2_MD SDC_MD(2)
47#define SDC3_MD SDC_MD(3)
48#define SDC4_MD SDC_MD(4)
49#define SDC5_MD SDC_MD(5)
50
51static void mmc_set_clk(unsigned ns, unsigned md)
52{
53 unsigned int val;
54 /*Clock Init*/
55 // 1. Set bit 7 in the NS registers
56 val = 1 << 7;
57 writel(val, SDC1_NS);
58
59 //2. Program MD registers
60 writel(md, SDC1_MD);
61
62 //3. Program NS resgister OR'd with Bit 7
63 val = 1 << 7;
64 val |= ns;
65 writel(val, SDC1_NS);
66
67 //4. Clear bit 7 of NS register
68 val = 1 << 7;
69 val = ~val;
70 val = val & readl(SDC1_NS);
71 writel(val, SDC1_NS);
72
73 //5. For MD != NA set bit 8 of NS register
74 val = 1 << 8;
75 val = val | readl(SDC1_NS);
76 writel(val, SDC1_NS);
77
78 //6. Set bit 11 in NS register
79 val = 1 << 11;
80 val = val | readl(SDC1_NS);
81 writel(val, SDC1_NS);
82
83 //7. Set bit 9 in NS register
84 val = 1 << 9;
85 val = val | readl(SDC1_NS);
86 writel(val, SDC1_NS);
87}
88
89
90void clock_set_enable (unsigned int mclk)
91{
Amol Jadica4f4c92011-01-13 20:19:34 -080092
93#ifdef PLATFORM_MSM8960
94 return;
95#endif
96
Shashank Mittal7afbf282010-06-02 19:48:31 -070097 if (mclk == MMC_CLK_400KHZ)
Shashank Mittal23b8f422010-04-16 19:27:21 -070098 {
99 mmc_set_clk(0x0010005B, 0x0001000F);
100 }
Shashank Mittal7afbf282010-06-02 19:48:31 -0700101 else if (mclk == MMC_CLK_20MHZ)
Shashank Mittal23b8f422010-04-16 19:27:21 -0700102 {
103 mmc_set_clk(0x00ED0043, 0x000100EC);
104 }
Shashank Mittal7afbf282010-06-02 19:48:31 -0700105 else if (mclk == MMC_CLK_48MHZ)
106 {
107 mmc_set_clk(0x00FE005B, 0x000100FD);
108 }
Shashank Mittal23b8f422010-04-16 19:27:21 -0700109}