Nokia RX-51: Fix crashing in U-Boot mmc function omap_hsmmc_stop_clock()
[platform/kernel/u-boot.git] / board / nokia / rx51 / rx51.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2012
4  * Ивайло Димитров <freemangordon@abv.bg>
5  *
6  * (C) Copyright 2011-2012
7  * Pali Rohár <pali@kernel.org>
8  *
9  * (C) Copyright 2010
10  * Alistair Buxton <a.j.buxton@gmail.com>
11  *
12  * Derived from Beagle Board and 3430 SDP code:
13  * (C) Copyright 2004-2008
14  * Texas Instruments, <www.ti.com>
15  *
16  * Author :
17  *      Sunil Kumar <sunilsaini05@gmail.com>
18  *      Shashi Ranjan <shashiranjanmca05@gmail.com>
19  *
20  *      Richard Woodruff <r-woodruff2@ti.com>
21  *      Syed Mohammed Khasim <khasim@ti.com>
22  */
23
24 #include <common.h>
25 #include <dm.h>
26 #include <env.h>
27 #include <init.h>
28 #include <watchdog.h>
29 #include <malloc.h>
30 #include <twl4030.h>
31 #include <i2c.h>
32 #include <video_fb.h>
33 #include <asm/io.h>
34 #include <asm/setup.h>
35 #include <asm/bitops.h>
36 #include <asm/mach-types.h>
37 #include <asm/omap_i2c.h>
38 #include <asm/arch/mux.h>
39 #include <asm/arch/sys_proto.h>
40 #include <asm/arch/mmc_host_def.h>
41
42 #include "rx51.h"
43 #include "tag_omap.h"
44
45 DECLARE_GLOBAL_DATA_PTR;
46
47 GraphicDevice gdev;
48
49 const omap3_sysinfo sysinfo = {
50         DDR_STACKED,
51         "Nokia RX-51",
52         "OneNAND"
53 };
54
55 /* This structure contains default omap tags needed for booting Maemo 5 */
56 static struct tag_omap omap[] = {
57         OMAP_TAG_UART_CONFIG(0x04),
58         OMAP_TAG_SERIAL_CONSOLE_CONFIG(0x03, 0x01C200),
59         OMAP_TAG_LCD_CONFIG("acx565akm", "internal", 90, 0x18),
60         OMAP_TAG_GPIO_SWITCH_CONFIG("cam_focus", 0x44, 0x1, 0x2, 0x0),
61         OMAP_TAG_GPIO_SWITCH_CONFIG("cam_launch", 0x45, 0x1, 0x2, 0x0),
62         OMAP_TAG_GPIO_SWITCH_CONFIG("cam_shutter", 0x6e, 0x1, 0x0, 0x0),
63         OMAP_TAG_GPIO_SWITCH_CONFIG("cmt_apeslpx", 0x46, 0x2, 0x2, 0x0),
64         OMAP_TAG_GPIO_SWITCH_CONFIG("cmt_bsi", 0x9d, 0x2, 0x2, 0x0),
65         OMAP_TAG_GPIO_SWITCH_CONFIG("cmt_en", 0x4a, 0x2, 0x2, 0x0),
66         OMAP_TAG_GPIO_SWITCH_CONFIG("cmt_rst", 0x4b, 0x6, 0x2, 0x0),
67         OMAP_TAG_GPIO_SWITCH_CONFIG("cmt_rst_rq", 0x49, 0x6, 0x2, 0x0),
68         OMAP_TAG_GPIO_SWITCH_CONFIG("cmt_wddis", 0x0d, 0x2, 0x2, 0x0),
69         OMAP_TAG_GPIO_SWITCH_CONFIG("headphone", 0xb1, 0x1, 0x1, 0x0),
70         OMAP_TAG_GPIO_SWITCH_CONFIG("kb_lock", 0x71, 0x1, 0x0, 0x0),
71         OMAP_TAG_GPIO_SWITCH_CONFIG("proximity", 0x59, 0x0, 0x0, 0x0),
72         OMAP_TAG_GPIO_SWITCH_CONFIG("sleep_ind", 0xa2, 0x2, 0x2, 0x0),
73         OMAP_TAG_GPIO_SWITCH_CONFIG("slide", GPIO_SLIDE, 0x0, 0x0, 0x0),
74         OMAP_TAG_WLAN_CX3110X_CONFIG(0x25, 0xff, 87, 42, -1),
75         OMAP_TAG_PARTITION_CONFIG("bootloader", 128 * 1024, 0x00000000, 0x00000003),
76         OMAP_TAG_PARTITION_CONFIG("config", 384 * 1024, 0x00020000, 0x00000000),
77         OMAP_TAG_PARTITION_CONFIG("log", 256 * 1024, 0x00080000, 0x00000000),
78         OMAP_TAG_PARTITION_CONFIG("kernel", 2 * 1024*1024, 0x000c0000, 0x00000000),
79         OMAP_TAG_PARTITION_CONFIG("initfs", 2 * 1024*1024, 0x002c0000, 0x00000000),
80         OMAP_TAG_PARTITION_CONFIG("rootfs", 257280 * 1024, 0x004c0000, 0x00000000),
81         OMAP_TAG_BOOT_REASON_CONFIG("pwr_key"),
82         OMAP_TAG_VERSION_STR_CONFIG("product", "RX-51"),
83         OMAP_TAG_VERSION_STR_CONFIG("hw-build", "2101"),
84         OMAP_TAG_VERSION_STR_CONFIG("nolo", "1.4.14"),
85         OMAP_TAG_VERSION_STR_CONFIG("boot-mode", "normal"),
86         { }
87 };
88
89 static char *boot_reason_ptr;
90 static char *hw_build_ptr;
91 static char *nolo_version_ptr;
92 static char *boot_mode_ptr;
93 static int serial_was_console_enabled;
94
95 /*
96  * Routine: init_omap_tags
97  * Description: Initialize pointers to values in tag_omap
98  */
99 static void init_omap_tags(void)
100 {
101         char *component;
102         char *version;
103         int i = 0;
104         while (omap[i].hdr.tag) {
105                 switch (omap[i].hdr.tag) {
106                 case OMAP_TAG_BOOT_REASON:
107                         boot_reason_ptr = omap[i].u.boot_reason.reason_str;
108                         break;
109                 case OMAP_TAG_VERSION_STR:
110                         component = omap[i].u.version.component;
111                         version = omap[i].u.version.version;
112                         if (strcmp(component, "hw-build") == 0)
113                                 hw_build_ptr = version;
114                         else if (strcmp(component, "nolo") == 0)
115                                 nolo_version_ptr = version;
116                         else if (strcmp(component, "boot-mode") == 0)
117                                 boot_mode_ptr = version;
118                         break;
119                 default:
120                         break;
121                 }
122                 i++;
123         }
124 }
125
126 static void reuse_omap_atags(struct tag_omap *t)
127 {
128         char *component;
129         char *version;
130         while (t->hdr.tag) {
131                 switch (t->hdr.tag) {
132                 case OMAP_TAG_BOOT_REASON:
133                         memset(boot_reason_ptr, 0, 12);
134                         strcpy(boot_reason_ptr, t->u.boot_reason.reason_str);
135                         break;
136                 case OMAP_TAG_VERSION_STR:
137                         component = t->u.version.component;
138                         version = t->u.version.version;
139                         if (strcmp(component, "hw-build") == 0) {
140                                 memset(hw_build_ptr, 0, 12);
141                                 strcpy(hw_build_ptr, version);
142                         } else if (strcmp(component, "nolo") == 0) {
143                                 memset(nolo_version_ptr, 0, 12);
144                                 strcpy(nolo_version_ptr, version);
145                         } else if (strcmp(component, "boot-mode") == 0) {
146                                 memset(boot_mode_ptr, 0, 12);
147                                 strcpy(boot_mode_ptr, version);
148                         }
149                         break;
150                 case OMAP_TAG_UART:
151                         if (t->u.uart.enabled_uarts)
152                                 serial_was_console_enabled = 1;
153                         break;
154                 case OMAP_TAG_SERIAL_CONSOLE:
155                         serial_was_console_enabled = 1;
156                         break;
157                 default:
158                         break;
159                 }
160                 t = tag_omap_next(t);
161         }
162 }
163
164 /*
165  * Routine: reuse_atags
166  * Description: Reuse atags from previous bootloader.
167  *              Reuse only only HW build, boot reason, boot mode and nolo
168  */
169 static void reuse_atags(void)
170 {
171         struct tag *t = (struct tag *)gd->bd->bi_boot_params;
172
173         /* First tag must be ATAG_CORE */
174         if (t->hdr.tag != ATAG_CORE)
175                 return;
176
177         if (!boot_reason_ptr || !hw_build_ptr)
178                 return;
179
180         /* Last tag must be ATAG_NONE */
181         while (t->hdr.tag != ATAG_NONE) {
182                 switch (t->hdr.tag) {
183                 case ATAG_REVISION:
184                         memset(hw_build_ptr, 0, 12);
185                         sprintf(hw_build_ptr, "%x", t->u.revision.rev);
186                         break;
187                 case ATAG_BOARD:
188                         reuse_omap_atags((struct tag_omap *)&t->u);
189                         break;
190                 default:
191                         break;
192                 }
193                 t = tag_next(t);
194         }
195 }
196
197 /*
198  * Routine: board_init
199  * Description: Early hardware init.
200  */
201 int board_init(void)
202 {
203         /* in SRAM or SDRAM, finish GPMC */
204         gpmc_init();
205         /* Enable the clks & power */
206         per_clocks_enable();
207         /* boot param addr */
208         gd->bd->bi_boot_params = OMAP34XX_SDRC_CS0 + 0x100;
209         return 0;
210 }
211
212 /*
213  * Routine: get_board_revision
214  * Description: Return board revision.
215  */
216 u32 get_board_rev(void)
217 {
218         return simple_strtol(hw_build_ptr, NULL, 16);
219 }
220
221 /*
222  * Routine: setup_board_tags
223  * Description: Append board specific boot tags.
224  */
225 void setup_board_tags(struct tag **in_params)
226 {
227         int setup_console_atag;
228         char *setup_boot_reason_atag;
229         char *setup_boot_mode_atag;
230         char *str;
231         int i;
232         int size;
233         int total_size;
234         struct tag *params;
235         struct tag_omap *t;
236
237         params = (struct tag *)gd->bd->bi_boot_params;
238
239         params->u.core.flags = 0x0;
240         params->u.core.pagesize = 0x1000;
241         params->u.core.rootdev = 0x0;
242
243         /* append omap atag only if env setup_omap_atag is set to 1 */
244         str = env_get("setup_omap_atag");
245         if (!str || str[0] != '1')
246                 return;
247
248         str = env_get("setup_console_atag");
249         if (str && str[0]) {
250                 if (str[0] == '1')
251                         setup_console_atag = 1;
252                 else
253                         setup_console_atag = 0;
254         } else {
255                 if (serial_was_console_enabled)
256                         setup_console_atag = 1;
257                 else
258                         setup_console_atag = 0;
259         }
260
261         setup_boot_reason_atag = env_get("setup_boot_reason_atag");
262         setup_boot_mode_atag = env_get("setup_boot_mode_atag");
263
264         params = *in_params;
265         t = (struct tag_omap *)&params->u;
266         total_size = sizeof(struct tag_header);
267
268         for (i = 0; omap[i].hdr.tag; i++) {
269
270                 /* skip serial console tag */
271                 if (!setup_console_atag &&
272                         omap[i].hdr.tag == OMAP_TAG_SERIAL_CONSOLE)
273                         continue;
274
275                 size = omap[i].hdr.size + sizeof(struct tag_omap_header);
276                 memcpy(t, &omap[i], size);
277
278                 /* set uart tag to 0 - disable serial console */
279                 if (!setup_console_atag && omap[i].hdr.tag == OMAP_TAG_UART)
280                         t->u.uart.enabled_uarts = 0;
281
282                 /* change boot reason */
283                 if (setup_boot_reason_atag &&
284                         omap[i].hdr.tag == OMAP_TAG_BOOT_REASON) {
285                         memset(t->u.boot_reason.reason_str, 0, 12);
286                         strcpy(t->u.boot_reason.reason_str,
287                                 setup_boot_reason_atag);
288                 }
289
290                 /* change boot mode */
291                 if (setup_boot_mode_atag &&
292                         omap[i].hdr.tag == OMAP_TAG_VERSION_STR &&
293                         strcmp(omap[i].u.version.component, "boot-mode") == 0) {
294                         memset(t->u.version.version, 0, 12);
295                         strcpy(t->u.version.version, setup_boot_mode_atag);
296                 }
297
298                 total_size += size;
299                 t = tag_omap_next(t);
300
301         }
302
303         params->hdr.tag = ATAG_BOARD;
304         params->hdr.size = total_size >> 2;
305         params = tag_next(params);
306
307         *in_params = params;
308 }
309
310 /*
311  * Routine: video_hw_init
312  * Description: Set up the GraphicDevice depending on sys_boot.
313  */
314 void *video_hw_init(void)
315 {
316         /* fill in Graphic Device */
317         gdev.frameAdrs = 0x8f9c0000;
318         gdev.winSizeX = 800;
319         gdev.winSizeY = 480;
320         gdev.gdfBytesPP = 2;
321         gdev.gdfIndex = GDF_16BIT_565RGB;
322         memset((void *)gdev.frameAdrs, 0, 0xbb800);
323         return (void *) &gdev;
324 }
325
326 /*
327  * Routine: twl4030_regulator_set_mode
328  * Description: Set twl4030 regulator mode over i2c powerbus.
329  */
330 static void twl4030_regulator_set_mode(u8 id, u8 mode)
331 {
332         u16 msg = MSG_SINGULAR(DEV_GRP_P1, id, mode);
333         twl4030_i2c_write_u8(TWL4030_CHIP_PM_MASTER,
334                              TWL4030_PM_MASTER_PB_WORD_MSB, msg >> 8);
335         twl4030_i2c_write_u8(TWL4030_CHIP_PM_MASTER,
336                              TWL4030_PM_MASTER_PB_WORD_LSB, msg & 0xff);
337 }
338
339 static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
340 {
341         u32 i, num_params = *parameters;
342         u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
343
344         /*
345          * copy the parameters to an un-cached area to avoid coherency
346          * issues
347          */
348         for (i = 0; i < num_params; i++) {
349                 __raw_writel(*parameters, sram_scratch_space);
350                 parameters++;
351                 sram_scratch_space++;
352         }
353
354         /* Now make the PPA call */
355         do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
356 }
357
358 void omap3_set_aux_cr_secure(u32 acr)
359 {
360         struct emu_hal_params_rx51 emu_romcode_params = { 0, };
361
362         emu_romcode_params.num_params = 2;
363         emu_romcode_params.param1 = acr;
364
365         omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
366                                (u32 *)&emu_romcode_params);
367 }
368
369 /*
370  * Routine: omap3_update_aux_cr_secure_rx51
371  * Description: Modify the contents Auxiliary Control Register.
372  * Parameters:
373  *   set_bits - bits to set in ACR
374  *   clr_bits - bits to clear in ACR
375  */
376 static void omap3_update_aux_cr_secure_rx51(u32 set_bits, u32 clear_bits)
377 {
378         u32 acr;
379
380         /* Read ACR */
381         asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
382         acr &= ~clear_bits;
383         acr |= set_bits;
384         omap3_set_aux_cr_secure(acr);
385 }
386
387 /*
388  * Routine: misc_init_r
389  * Description: Configure board specific parts.
390  */
391 int misc_init_r(void)
392 {
393         struct udevice *dev;
394         char buf[12];
395         u8 state;
396
397         /* reset lp5523 led */
398         if (i2c_get_chip_for_busnum(1, 0x32, 1, &dev) == 0)
399                 dm_i2c_reg_write(dev, 0x3d, 0xff);
400
401         /* initialize twl4030 power managment */
402         twl4030_power_init();
403
404         /* set VSIM to 1.8V */
405         twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VSIM_DEDICATED,
406                                 TWL4030_PM_RECEIVER_VSIM_VSEL_18,
407                                 TWL4030_PM_RECEIVER_VSIM_DEV_GRP,
408                                 TWL4030_PM_RECEIVER_DEV_GRP_P1);
409
410         /* store I2C access state */
411         twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER, TWL4030_PM_MASTER_PB_CFG,
412                             &state);
413
414         /* enable I2C access to powerbus (needed for twl4030 regulator) */
415         twl4030_i2c_write_u8(TWL4030_CHIP_PM_MASTER, TWL4030_PM_MASTER_PB_CFG,
416                              0x02);
417
418         /* set VAUX3, VSIM and VMMC1 state to active - enable eMMC memory */
419         twl4030_regulator_set_mode(RES_VAUX3, RES_STATE_ACTIVE);
420         twl4030_regulator_set_mode(RES_VSIM, RES_STATE_ACTIVE);
421         twl4030_regulator_set_mode(RES_VMMC1, RES_STATE_ACTIVE);
422
423         /* restore I2C access state */
424         twl4030_i2c_write_u8(TWL4030_CHIP_PM_MASTER, TWL4030_PM_MASTER_PB_CFG,
425                              state);
426
427         /* set env variable attkernaddr for relocated kernel */
428         sprintf(buf, "%#x", KERNEL_ADDRESS);
429         env_set("attkernaddr", buf);
430
431         /* initialize omap tags */
432         init_omap_tags();
433
434         /* reuse atags from previous bootloader */
435         reuse_atags();
436
437         omap_die_id_display();
438         print_cpuinfo();
439
440         /*
441          * Cortex-A8(r1p0..r1p2) errata 430973 workaround
442          * Set IBE bit in Auxiliary Control Register
443          *
444          * Call this routine only on real secure device
445          * Qemu does not implement secure PPA and crash
446          */
447         if (get_device_type() == HS_DEVICE)
448                 omap3_update_aux_cr_secure_rx51(1 << 6, 0);
449
450         return 0;
451 }
452
453 /*
454  * Routine: set_muxconf_regs
455  * Description: Setting up the configuration Mux registers specific to the
456  *              hardware. Many pins need to be moved from protect to primary
457  *              mode.
458  */
459 void set_muxconf_regs(void)
460 {
461         MUX_RX51();
462 }
463
464 static unsigned long int twl_wd_time; /* last time of watchdog reset */
465 static unsigned long int twl_i2c_lock;
466
467 /*
468  * Routine: hw_watchdog_reset
469  * Description: Reset timeout of twl4030 watchdog.
470  */
471 void hw_watchdog_reset(void)
472 {
473         u8 timeout = 0;
474
475         /* do not reset watchdog too often - max every 4s */
476         if (get_timer(twl_wd_time) < 4 * CONFIG_SYS_HZ)
477                 return;
478
479         /* localy lock twl4030 i2c bus */
480         if (test_and_set_bit(0, &twl_i2c_lock))
481                 return;
482
483         /* read actual watchdog timeout */
484         twl4030_i2c_read_u8(TWL4030_CHIP_PM_RECEIVER,
485                             TWL4030_PM_RECEIVER_WATCHDOG_CFG, &timeout);
486
487         /* timeout 0 means watchdog is disabled */
488         /* reset watchdog timeout to 31s (maximum) */
489         if (timeout != 0)
490                 twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER,
491                                      TWL4030_PM_RECEIVER_WATCHDOG_CFG, 31);
492
493         /* store last watchdog reset time */
494         twl_wd_time = get_timer(0);
495
496         /* localy unlock twl4030 i2c bus */
497         test_and_clear_bit(0, &twl_i2c_lock);
498 }
499
500 /*
501  * TWL4030 keypad handler for cfb_console
502  */
503
504 static const char keymap[] = {
505         /* normal */
506         'q',  'o',  'p',  ',', '\b',    0,  'a',  's',
507         'w',  'd',  'f',  'g',  'h',  'j',  'k',  'l',
508         'e',  '.',    0,  '\r',   0,  'z',  'x',  'c',
509         'r',  'v',  'b',  'n',  'm',  ' ',  ' ',    0,
510         't',    0,    0,    0,    0,    0,    0,    0,
511         'y',    0,    0,    0,    0,    0,    0,    0,
512         'u',    0,    0,    0,    0,    0,    0,    0,
513         'i',    5,    6,    0,    0,    0,    0,    0,
514         /* fn */
515         '1',  '9',  '0',  '=', '\b',    0,  '*',  '+',
516         '2',  '#',  '-',  '_',  '(',  ')',  '&',  '!',
517         '3',  '?',  '^', '\r',    0,  156,  '$',  238,
518         '4',  '/', '\\',  '"', '\'',  '@',    0,  '<',
519         '5',  '|',  '>',    0,    0,    0,    0,    0,
520         '6',    0,    0,    0,    0,    0,    0,    0,
521         '7',    0,    0,    0,    0,    0,    0,    0,
522         '8',   16,   17,    0,    0,    0,    0,    0,
523 };
524
525 static u8 keys[8];
526 static u8 old_keys[8] = {0, 0, 0, 0, 0, 0, 0, 0};
527 #define KEYBUF_SIZE 32
528 static u8 keybuf[KEYBUF_SIZE];
529 static u8 keybuf_head;
530 static u8 keybuf_tail;
531
532 /*
533  * Routine: rx51_kp_init
534  * Description: Initialize HW keyboard.
535  */
536 int rx51_kp_init(void)
537 {
538         int ret = 0;
539         u8 ctrl;
540         ret = twl4030_i2c_read_u8(TWL4030_CHIP_KEYPAD,
541                                   TWL4030_KEYPAD_KEYP_CTRL_REG, &ctrl);
542
543         if (ret)
544                 return ret;
545
546         /* turn on keyboard and use hardware scanning */
547         ctrl |= TWL4030_KEYPAD_CTRL_KBD_ON;
548         ctrl |= TWL4030_KEYPAD_CTRL_SOFT_NRST;
549         ctrl |= TWL4030_KEYPAD_CTRL_SOFTMODEN;
550         ret |= twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
551                                     TWL4030_KEYPAD_KEYP_CTRL_REG, ctrl);
552         /* enable key event status */
553         ret |= twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
554                                     TWL4030_KEYPAD_KEYP_IMR1, 0xfe);
555         /* enable interrupt generation on rising and falling */
556         /* this is a workaround for qemu twl4030 emulation */
557         ret |= twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
558                                     TWL4030_KEYPAD_KEYP_EDR, 0x57);
559         /* enable ISR clear on read */
560         ret |= twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
561                                     TWL4030_KEYPAD_KEYP_SIH_CTRL, 0x05);
562         return 0;
563 }
564
565 static void rx51_kp_fill(u8 k, u8 mods)
566 {
567         /* check if some cursor key without meta fn key was pressed */
568         if (!(mods & 2) && (k == 18 || k == 31 || k == 33 || k == 34)) {
569                 keybuf[keybuf_tail++] = '\e';
570                 keybuf_tail %= KEYBUF_SIZE;
571                 keybuf[keybuf_tail++] = '[';
572                 keybuf_tail %= KEYBUF_SIZE;
573                 if (k == 18) /* up */
574                         keybuf[keybuf_tail++] = 'A';
575                 else if (k == 31) /* left */
576                         keybuf[keybuf_tail++] = 'D';
577                 else if (k == 33) /* down */
578                         keybuf[keybuf_tail++] = 'B';
579                 else if (k == 34) /* right */
580                         keybuf[keybuf_tail++] = 'C';
581                 keybuf_tail %= KEYBUF_SIZE;
582                 return;
583         }
584
585         if (mods & 2) { /* fn meta key was pressed */
586                 k = keymap[k+64];
587         } else {
588                 k = keymap[k];
589                 if (mods & 1) { /* ctrl key was pressed */
590                         if (k >= 'a' && k <= 'z')
591                                 k -= 'a' - 1;
592                 }
593                 if (mods & 4) { /* shift key was pressed */
594                         if (k >= 'a' && k <= 'z')
595                                 k += 'A' - 'a';
596                         else if (k == '.')
597                                 k = ':';
598                         else if (k == ',')
599                                 k = ';';
600                 }
601         }
602         keybuf[keybuf_tail++] = k;
603         keybuf_tail %= KEYBUF_SIZE;
604 }
605
606 /*
607  * Routine: rx51_kp_tstc
608  * Description: Test if key was pressed (from buffer).
609  */
610 int rx51_kp_tstc(struct stdio_dev *sdev)
611 {
612         u8 c, r, dk, i;
613         u8 intr;
614         u8 mods;
615
616         /* localy lock twl4030 i2c bus */
617         if (test_and_set_bit(0, &twl_i2c_lock))
618                 return 0;
619
620         /* twl4030 remembers up to 2 events */
621         for (i = 0; i < 2; i++) {
622
623                 /* check interrupt register for events */
624                 twl4030_i2c_read_u8(TWL4030_CHIP_KEYPAD,
625                                     TWL4030_KEYPAD_KEYP_ISR1 + (2 * i), &intr);
626
627                 /* no event */
628                 if (!(intr&1))
629                         continue;
630
631                 /* read the key state */
632                 twl4030_i2c_read(TWL4030_CHIP_KEYPAD,
633                                  TWL4030_KEYPAD_FULL_CODE_7_0, keys, 8);
634
635                 /* cut out modifier keys from the keystate */
636                 mods = keys[4] >> 4;
637                 keys[4] &= 0x0f;
638
639                 for (c = 0; c < 8; c++) {
640
641                         /* get newly pressed keys only */
642                         dk = ((keys[c] ^ old_keys[c])&keys[c]);
643                         old_keys[c] = keys[c];
644
645                         /* fill the keybuf */
646                         for (r = 0; r < 8; r++) {
647                                 if (dk&1)
648                                         rx51_kp_fill((c*8)+r, mods);
649                                 dk = dk >> 1;
650                         }
651
652                 }
653
654         }
655
656         /* localy unlock twl4030 i2c bus */
657         test_and_clear_bit(0, &twl_i2c_lock);
658
659         return (KEYBUF_SIZE + keybuf_tail - keybuf_head)%KEYBUF_SIZE;
660 }
661
662 /*
663  * Routine: rx51_kp_getc
664  * Description: Get last pressed key (from buffer).
665  */
666 int rx51_kp_getc(struct stdio_dev *sdev)
667 {
668         keybuf_head %= KEYBUF_SIZE;
669         while (!rx51_kp_tstc(sdev))
670                 WATCHDOG_RESET();
671         return keybuf[keybuf_head++];
672 }
673
674 /*
675  * Routine: board_mmc_init
676  * Description: Initialize mmc devices.
677  */
678 int board_mmc_init(struct bd_info *bis)
679 {
680         omap_mmc_init(0, 0, 0, -1, -1);
681         omap_mmc_init(1, 0, 0, -1, -1);
682         return 0;
683 }
684
685 void board_mmc_power_init(void)
686 {
687         twl4030_power_mmc_init(0);
688         twl4030_power_mmc_init(1);
689 }
690
691 static const struct omap_i2c_platdata rx51_i2c[] = {
692         { I2C_BASE1, 2200000, OMAP_I2C_REV_V1 },
693         { I2C_BASE2, 100000, OMAP_I2C_REV_V1 },
694         { I2C_BASE3, 400000, OMAP_I2C_REV_V1 },
695 };
696
697 U_BOOT_DEVICES(rx51_i2c) = {
698         { "i2c_omap", &rx51_i2c[0] },
699         { "i2c_omap", &rx51_i2c[1] },
700         { "i2c_omap", &rx51_i2c[2] },
701 };