arm:tegra:cardhu:Pass 8bit sd support info through plat data
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-sdhci.c
1 /*
2  * arch/arm/mach-tegra/board-harmony-sdhci.c
3  *
4  * Copyright (C) 2010 Google, Inc.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #include <linux/resource.h>
18 #include <linux/platform_device.h>
19 #include <linux/delay.h>
20 #include <linux/gpio.h>
21 #include <linux/clk.h>
22 #include <linux/err.h>
23 #include <linux/mmc/host.h>
24
25 #include <asm/mach-types.h>
26 #include <mach/irqs.h>
27 #include <mach/iomap.h>
28 #include <mach/sdhci.h>
29
30 #include "gpio-names.h"
31 #include "board.h"
32
33 #define CARDHU_SD_CD TEGRA_GPIO_PI5
34 #define CARDHU_SD_WP TEGRA_GPIO_PT3
35
36 static struct resource sdhci_resource0[] = {
37         [0] = {
38                 .start  = INT_SDMMC1,
39                 .end    = INT_SDMMC1,
40                 .flags  = IORESOURCE_IRQ,
41         },
42         [1] = {
43                 .start  = TEGRA_SDMMC1_BASE,
44                 .end    = TEGRA_SDMMC1_BASE + TEGRA_SDMMC1_SIZE-1,
45                 .flags  = IORESOURCE_MEM,
46         },
47 };
48
49 static struct resource sdhci_resource2[] = {
50         [0] = {
51                 .start  = INT_SDMMC3,
52                 .end    = INT_SDMMC3,
53                 .flags  = IORESOURCE_IRQ,
54         },
55         [1] = {
56                 .start  = TEGRA_SDMMC3_BASE,
57                 .end    = TEGRA_SDMMC3_BASE + TEGRA_SDMMC3_SIZE-1,
58                 .flags  = IORESOURCE_MEM,
59         },
60 };
61
62 static struct resource sdhci_resource3[] = {
63         [0] = {
64                 .start  = INT_SDMMC4,
65                 .end    = INT_SDMMC4,
66                 .flags  = IORESOURCE_IRQ,
67         },
68         [1] = {
69                 .start  = TEGRA_SDMMC4_BASE,
70                 .end    = TEGRA_SDMMC4_BASE + TEGRA_SDMMC4_SIZE-1,
71                 .flags  = IORESOURCE_MEM,
72         },
73 };
74
75
76 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data0 = {
77         .clk_id = NULL,
78         .force_hs = 0,
79         .cd_gpio = -1,
80         .wp_gpio = -1,
81         .power_gpio = -1,
82         .tap_delay = 6,
83         .is_voltage_switch_supported = false,
84         .vsd_name = NULL,
85         .vsd_slot_name = NULL,
86         .max_clk = 48000000,
87         .is_8bit_supported = false,
88 };
89
90 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data2 = {
91         .clk_id = NULL,
92         .force_hs = 1,
93         .cd_gpio = -1,
94         .wp_gpio = -1,
95         .power_gpio = -1,
96         .tap_delay = 6,
97         .is_voltage_switch_supported = true,
98         .vsd_name = "vddio_sdmmc1",
99         .vsd_slot_name = "vddio_sd_slot",
100         .max_clk = 208000000,
101         .is_8bit_supported = false,
102 };
103
104 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data3 = {
105         .clk_id = NULL,
106         .force_hs = 0,
107         .cd_gpio = -1,
108         .wp_gpio = -1,
109         .power_gpio = -1,
110         .tap_delay = 6,
111         .is_voltage_switch_supported = false,
112         .vsd_name = NULL,
113         .vsd_slot_name = NULL,
114         .max_clk = 48000000,
115         .is_8bit_supported = true,
116 };
117
118 static struct platform_device tegra_sdhci_device0 = {
119         .name           = "sdhci-tegra",
120         .id             = 0,
121         .resource       = sdhci_resource0,
122         .num_resources  = ARRAY_SIZE(sdhci_resource0),
123         .dev = {
124                 .platform_data = &tegra_sdhci_platform_data0,
125         },
126 };
127
128 static struct platform_device tegra_sdhci_device2 = {
129         .name           = "sdhci-tegra",
130         .id             = 2,
131         .resource       = sdhci_resource2,
132         .num_resources  = ARRAY_SIZE(sdhci_resource2),
133         .dev = {
134                 .platform_data = &tegra_sdhci_platform_data2,
135         },
136 };
137
138 static struct platform_device tegra_sdhci_device3 = {
139         .name           = "sdhci-tegra",
140         .id             = 3,
141         .resource       = sdhci_resource3,
142         .num_resources  = ARRAY_SIZE(sdhci_resource3),
143         .dev = {
144                 .platform_data = &tegra_sdhci_platform_data3,
145         },
146 };
147
148 static int cardhu_sd_cd_gpio_init(void)
149 {
150         unsigned int rc = 0;
151
152         rc = gpio_request(CARDHU_SD_CD, "card_detect");
153         if (rc) {
154                 pr_err("Card detect gpio request failed:%d\n", rc);
155                 return rc;
156         }
157
158         tegra_gpio_enable(CARDHU_SD_CD);
159
160         rc = gpio_direction_input(CARDHU_SD_CD);
161         if (rc) {
162                 pr_err("Unable to configure direction for card detect gpio:%d\n", rc);
163                 return rc;
164         }
165
166         return 0;
167 }
168
169 static int cardhu_sd_wp_gpio_init(void)
170 {
171         unsigned int rc = 0;
172
173         rc = gpio_request(CARDHU_SD_WP, "write_protect");
174         if (rc) {
175                 pr_err("Write protect gpio request failed:%d\n", rc);
176                 return rc;
177         }
178
179         tegra_gpio_enable(CARDHU_SD_WP);
180
181         rc = gpio_direction_input(CARDHU_SD_WP);
182         if (rc) {
183                 pr_err("Unable to configure direction for write protect gpio:%d\n", rc);
184                 return rc;
185         }
186
187         return 0;
188 }
189
190 int __init cardhu_sdhci_init(void)
191 {
192         unsigned int rc = 0;
193         platform_device_register(&tegra_sdhci_device3);
194         platform_device_register(&tegra_sdhci_device2);
195
196         /* Fix ME: The gpios have to enabled for hot plug support */
197         rc = cardhu_sd_cd_gpio_init();
198         if (!rc) {
199                 tegra_sdhci_platform_data0.cd_gpio = CARDHU_SD_CD;
200                 tegra_sdhci_platform_data0.cd_gpio_polarity = 0;
201         }
202         rc = cardhu_sd_wp_gpio_init();
203         if (!rc) {
204                 tegra_sdhci_platform_data0.wp_gpio = CARDHU_SD_WP;
205                 tegra_sdhci_platform_data0.wp_gpio_polarity = 1;
206         }
207
208         platform_device_register(&tegra_sdhci_device0);
209         return 0;
210 }