]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-n800-mmc.c
Merge branch 'omap-fixes'
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-n800-mmc.c
1 /*
2  * linux/arch/arm/mach-omap2/board-n800-mmc.c
3  *
4  * Copyright (C) 2006 Nokia Corporation
5  * Author: Juha Yrjola
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/delay.h>
13 #include <linux/platform_device.h>
14 #include <linux/gpio.h>
15 #include <linux/i2c/menelaus.h>
16
17 #include <asm/mach-types.h>
18
19 #include <mach/mmc.h>
20
21 #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
22
23 static const int slot_switch_gpio = 96;
24
25 static const int n810_slot2_pw_vddf = 23;
26 static const int n810_slot2_pw_vdd = 9;
27
28 static int slot1_cover_open;
29 static int slot2_cover_open;
30 static struct device *mmc_device;
31
32 /*
33  * VMMC   --> slot 1 (N800 & N810)
34  * VDCDC3_APE, VMCS2_APE --> slot 2 on N800
35  * GPIO96 --> Menelaus GPIO2
36  * GPIO23 --> controls slot2 VSD    (N810 only)
37  * GPIO9  --> controls slot2 VIO_SD (N810 only)
38  */
39
40 static int n800_mmc_switch_slot(struct device *dev, int slot)
41 {
42 #ifdef CONFIG_MMC_DEBUG
43         dev_dbg(dev, "Choose slot %d\n", slot + 1);
44 #endif
45         gpio_set_value(slot_switch_gpio, slot);
46         return 0;
47 }
48
49 static int n800_mmc_set_power_menelaus(struct device *dev, int slot,
50                                         int power_on, int vdd)
51 {
52         int mV;
53
54 #ifdef CONFIG_MMC_DEBUG
55         dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1,
56                 power_on ? "on" : "off", vdd);
57 #endif
58         if (slot == 0) {
59                 if (!power_on)
60                         return menelaus_set_vmmc(0);
61                 switch (1 << vdd) {
62                 case MMC_VDD_33_34:
63                 case MMC_VDD_32_33:
64                 case MMC_VDD_31_32:
65                         mV = 3100;
66                         break;
67                 case MMC_VDD_30_31:
68                         mV = 3000;
69                         break;
70                 case MMC_VDD_28_29:
71                         mV = 2800;
72                         break;
73                 case MMC_VDD_165_195:
74                         mV = 1850;
75                         break;
76                 default:
77                         BUG();
78                 }
79                 return menelaus_set_vmmc(mV);
80         } else {
81                 if (!power_on)
82                         return menelaus_set_vdcdc(3, 0);
83                 switch (1 << vdd) {
84                 case MMC_VDD_33_34:
85                 case MMC_VDD_32_33:
86                         mV = 3300;
87                         break;
88                 case MMC_VDD_30_31:
89                 case MMC_VDD_29_30:
90                         mV = 3000;
91                         break;
92                 case MMC_VDD_28_29:
93                 case MMC_VDD_27_28:
94                         mV = 2800;
95                         break;
96                 case MMC_VDD_24_25:
97                 case MMC_VDD_23_24:
98                         mV = 2400;
99                         break;
100                 case MMC_VDD_22_23:
101                 case MMC_VDD_21_22:
102                         mV = 2200;
103                         break;
104                 case MMC_VDD_20_21:
105                         mV = 2000;
106                         break;
107                 case MMC_VDD_165_195:
108                         mV = 1800;
109                         break;
110                 default:
111                         BUG();
112                 }
113                 return menelaus_set_vdcdc(3, mV);
114         }
115         return 0;
116 }
117
118 static void nokia_mmc_set_power_internal(struct device *dev,
119                                          int power_on)
120 {
121         dev_dbg(dev, "Set internal slot power %s\n",
122                 power_on ? "on" : "off");
123
124         if (power_on) {
125                 gpio_set_value(n810_slot2_pw_vddf, 1);
126                 udelay(30);
127                 gpio_set_value(n810_slot2_pw_vdd, 1);
128                 udelay(100);
129         } else {
130                 gpio_set_value(n810_slot2_pw_vdd, 0);
131                 msleep(50);
132                 gpio_set_value(n810_slot2_pw_vddf, 0);
133                 msleep(50);
134         }
135 }
136
137 static int n800_mmc_set_power(struct device *dev, int slot, int power_on,
138                               int vdd)
139 {
140         if (machine_is_nokia_n800() || slot == 0)
141                 return n800_mmc_set_power_menelaus(dev, slot, power_on, vdd);
142
143         nokia_mmc_set_power_internal(dev, power_on);
144
145         return 0;
146 }
147
148 static int n800_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)
149 {
150         int r;
151
152         dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1,
153                 bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");
154         BUG_ON(slot != 0 && slot != 1);
155         slot++;
156         switch (bus_mode) {
157         case MMC_BUSMODE_OPENDRAIN:
158                 r = menelaus_set_mmc_opendrain(slot, 1);
159                 break;
160         case MMC_BUSMODE_PUSHPULL:
161                 r = menelaus_set_mmc_opendrain(slot, 0);
162                 break;
163         default:
164                 BUG();
165         }
166         if (r != 0 && printk_ratelimit())
167                 dev_err(dev, "MMC: unable to set bus mode for slot %d\n",
168                         slot);
169         return r;
170 }
171
172 static int n800_mmc_get_cover_state(struct device *dev, int slot)
173 {
174         slot++;
175         BUG_ON(slot != 1 && slot != 2);
176         if (slot == 1)
177                 return slot1_cover_open;
178         else
179                 return slot2_cover_open;
180 }
181
182 static void n800_mmc_callback(void *data, u8 card_mask)
183 {
184         int bit, *openp, index;
185
186         if (machine_is_nokia_n800()) {
187                 bit = 1 << 1;
188                 openp = &slot2_cover_open;
189                 index = 1;
190         } else {
191                 bit = 1;
192                 openp = &slot1_cover_open;
193                 index = 0;
194         }
195
196         if (card_mask & bit)
197                 *openp = 1;
198         else
199                 *openp = 0;
200
201         omap_mmc_notify_cover_event(mmc_device, index, *openp);
202 }
203
204 void n800_mmc_slot1_cover_handler(void *arg, int closed_state)
205 {
206         if (mmc_device == NULL)
207                 return;
208
209         slot1_cover_open = !closed_state;
210         omap_mmc_notify_cover_event(mmc_device, 0, closed_state);
211 }
212
213 static int n800_mmc_late_init(struct device *dev)
214 {
215         int r, bit, *openp;
216         int vs2sel;
217
218         mmc_device = dev;
219
220         r = menelaus_set_slot_sel(1);
221         if (r < 0)
222                 return r;
223
224         if (machine_is_nokia_n800())
225                 vs2sel = 0;
226         else
227                 vs2sel = 2;
228
229         r = menelaus_set_mmc_slot(2, 0, vs2sel, 1);
230         if (r < 0)
231                 return r;
232
233         n800_mmc_set_power(dev, 0, MMC_POWER_ON, 16); /* MMC_VDD_28_29 */
234         n800_mmc_set_power(dev, 1, MMC_POWER_ON, 16);
235
236         r = menelaus_set_mmc_slot(1, 1, 0, 1);
237         if (r < 0)
238                 return r;
239         r = menelaus_set_mmc_slot(2, 1, vs2sel, 1);
240         if (r < 0)
241                 return r;
242
243         r = menelaus_get_slot_pin_states();
244         if (r < 0)
245                 return r;
246
247         if (machine_is_nokia_n800()) {
248                 bit = 1 << 1;
249                 openp = &slot2_cover_open;
250         } else {
251                 bit = 1;
252                 openp = &slot1_cover_open;
253                 slot2_cover_open = 0;
254         }
255
256         /* All slot pin bits seem to be inversed until first swith change */
257         if (r == 0xf || r == (0xf & ~bit))
258                 r = ~r;
259
260         if (r & bit)
261                 *openp = 1;
262         else
263                 *openp = 0;
264
265         r = menelaus_register_mmc_callback(n800_mmc_callback, NULL);
266
267         return r;
268 }
269
270 static void n800_mmc_shutdown(struct device *dev)
271 {
272         int vs2sel;
273
274         if (machine_is_nokia_n800())
275                 vs2sel = 0;
276         else
277                 vs2sel = 2;
278
279         menelaus_set_mmc_slot(1, 0, 0, 0);
280         menelaus_set_mmc_slot(2, 0, vs2sel, 0);
281 }
282
283 static void n800_mmc_cleanup(struct device *dev)
284 {
285         menelaus_unregister_mmc_callback();
286
287         gpio_free(slot_switch_gpio);
288
289         if (machine_is_nokia_n810()) {
290                 gpio_free(n810_slot2_pw_vddf);
291                 gpio_free(n810_slot2_pw_vdd);
292         }
293 }
294
295 /*
296  * MMC controller1 has two slots that are multiplexed via I2C.
297  * MMC controller2 is not in use.
298  */
299 static struct omap_mmc_platform_data mmc1_data = {
300         .nr_slots               = 2,
301         .switch_slot            = n800_mmc_switch_slot,
302         .init                   = n800_mmc_late_init,
303         .cleanup                = n800_mmc_cleanup,
304         .shutdown               = n800_mmc_shutdown,
305         .max_freq               = 24000000,
306         .dma_mask               = 0xffffffff,
307         .slots[0] = {
308                 .wires          = 4,
309                 .set_power      = n800_mmc_set_power,
310                 .set_bus_mode   = n800_mmc_set_bus_mode,
311                 .get_cover_state= n800_mmc_get_cover_state,
312                 .ocr_mask       = MMC_VDD_165_195 | MMC_VDD_30_31 |
313                                   MMC_VDD_32_33   | MMC_VDD_33_34,
314                 .name           = "internal",
315         },
316         .slots[1] = {
317                 .set_power      = n800_mmc_set_power,
318                 .set_bus_mode   = n800_mmc_set_bus_mode,
319                 .get_cover_state= n800_mmc_get_cover_state,
320                 .ocr_mask       = MMC_VDD_165_195 | MMC_VDD_20_21 |
321                                   MMC_VDD_21_22 | MMC_VDD_22_23 | MMC_VDD_23_24 |
322                                   MMC_VDD_24_25 | MMC_VDD_27_28 | MMC_VDD_28_29 |
323                                   MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_32_33 |
324                                   MMC_VDD_33_34,
325                 .name           = "external",
326         },
327 };
328
329 static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];
330
331 void __init n800_mmc_init(void)
332
333 {
334         if (machine_is_nokia_n810()) {
335                 mmc1_data.slots[0].name = "external";
336
337                 /*
338                  * Some Samsung Movinand chips do not like open-ended
339                  * multi-block reads and fall to braind-dead state
340                  * while doing so. Reducing the number of blocks in
341                  * the transfer or delays in clock disable do not help
342                  */
343                 mmc1_data.slots[1].name = "internal";
344                 mmc1_data.slots[1].ban_openended = 1;
345         }
346
347         if (gpio_request(slot_switch_gpio, "MMC slot switch") < 0)
348                 BUG();
349         gpio_direction_output(slot_switch_gpio, 0);
350
351         if (machine_is_nokia_n810()) {
352                 if (gpio_request(n810_slot2_pw_vddf, "MMC slot 2 Vddf") < 0)
353                         BUG();
354                 gpio_direction_output(n810_slot2_pw_vddf, 0);
355
356                 if (gpio_request(n810_slot2_pw_vdd, "MMC slot 2 Vdd") < 0)
357                         BUG();
358                 gpio_direction_output(n810_slot2_pw_vdd, 0);
359         }
360
361         mmc_data[0] = &mmc1_data;
362         omap2_init_mmc(mmc_data, OMAP24XX_NR_MMC);
363 }
364 #else
365
366 void __init n800_mmc_init(void)
367 {
368 }
369
370 void n800_mmc_slot1_cover_handler(void *arg, int state)
371 {
372 }
373
374 #endif