The complex patch with which MohammadAG had his success
[h-e-n] / arch / arm / mach-omap2 / board-rx51.c
1 /*
2  * linux/arch/arm/mach-omap2/board-rx51.c
3  *
4  * Copyright (C) 2007, 2008 Nokia
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/delay.h>
15 #include <linux/err.h>
16 #include <linux/clk.h>
17 #include <linux/omapfb.h>
18 #include <linux/usb/musb.h>
19
20 #include <mach/hardware.h>
21 #include <asm/mach-types.h>
22 #include <asm/mach/arch.h>
23 #include <asm/mach/map.h>
24
25 #include <mach/mcspi.h>
26 #include <mach/gpio.h>
27 #include <mach/mux.h>
28 #include <mach/board.h>
29 #include <mach/common.h>
30 #include <mach/keypad.h>
31 #include <mach/dma.h>
32 #include <mach/gpmc.h>
33 #include <mach/usb-musb.h>
34 #include <mach/omap-pm.h>
35 #include <mach/vram.h>
36
37 #include <asm/io.h>
38 #include <asm/delay.h>
39
40 #include "omap3-opp.h"
41 #include "pm.h"
42
43 #include <mach/pm.h>
44 #include <mach/omap-pm.h>
45 #include <mach/prcm.h>
46 #include "cm.h"
47
48 #define RX51_USB_TRANSCEIVER_RST_GPIO   67
49
50 extern int omap_init_fb(void);
51 extern void rx51_video_mem_init(void);
52
53 static struct omap_uart_config rx51_uart_config = {
54         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
55 };
56
57 static struct omap_board_config_kernel rx51_config[] = {
58         { OMAP_TAG_UART,        &rx51_uart_config },
59 };
60
61 static struct omap_bluetooth_config rx51_bt_config = {
62         .chip_type              = BT_CHIP_BCM,
63         .bt_wakeup_gpio         = 37,
64         .host_wakeup_gpio       = 101,
65         .reset_gpio             = 91,
66         .bt_uart                = 2,
67         .bt_sysclk              = BT_SYSCLK_38_4,
68 };
69
70 static void __init rx51_init_irq(void)
71 {
72         struct omap_sdrc_params *sdrc_params;
73
74         sdrc_params = rx51_get_sdram_timings();
75
76         omap2_init_common_hw(sdrc_params, sdrc_params,
77                              omap3_mpu_rate_table,
78                              omap3_dsp_rate_table,
79                              omap3_l3_rate_table);
80         omap_init_irq();
81         omap_gpio_init();
82 }
83
84 static void __init rx51_pm_init(void)
85 {
86         struct prm_setup_times prm_setup = {
87                 .clksetup = 111, /* must equal Volt offset + voltsetup2 */
88                 .voltsetup_time1 = 270,
89                 .voltsetup_time2 = 150,
90                 /* Time between wakeup event to when the sysoff goes high */
91                 .voltoffset = 16,
92                  /* The following is for a 2.25ms ramp time of the oscillator
93                   * Documented 2ms, added .25 as margin. NOTE: scripts
94                   * change as oscillator changes
95                   */
96                 .voltsetup2 = 95,
97         };
98
99         omap3_set_prm_setup_times(&prm_setup);
100 }
101
102 static void __init rx51_xceiv_init(void)
103 {
104         if (gpio_request(RX51_USB_TRANSCEIVER_RST_GPIO, NULL) < 0)
105                 BUG();
106         gpio_direction_output(RX51_USB_TRANSCEIVER_RST_GPIO, 1);
107 }
108
109 static int rx51_xceiv_reset(void)
110 {
111         printk(KERN_ERR "rx51_xceiv_reset\n");
112         /* make sure the transceiver is awake */
113         msleep(15);
114         /* only reset powered transceivers */
115         if (!gpio_get_value(RX51_USB_TRANSCEIVER_RST_GPIO))
116                 return 0;
117         gpio_set_value(RX51_USB_TRANSCEIVER_RST_GPIO, 0);
118         msleep(1);
119         gpio_set_value(RX51_USB_TRANSCEIVER_RST_GPIO, 1);
120         msleep(15);
121
122         return 0;
123 }
124
125 static int rx51_xceiv_power(bool power)
126 {
127         unsigned long   timeout;
128
129         printk(KERN_ERR "rx51_xceiv_power %d\n",power);
130         if (!power) {
131                 /* Let musb go stdby before powering down the transceiver */
132                 timeout = jiffies + msecs_to_jiffies(100);
133                 while (!time_after(jiffies, timeout))
134                         if (cm_read_mod_reg(CORE_MOD, CM_IDLEST1)
135                                 & OMAP3430ES2_ST_HSOTGUSB_STDBY_MASK)
136                                 break;
137                 if (!(cm_read_mod_reg(CORE_MOD, CM_IDLEST1)
138                         & OMAP3430ES2_ST_HSOTGUSB_STDBY_MASK))
139                         WARN(1, "could not put musb to sleep\n");
140         }
141         gpio_set_value(RX51_USB_TRANSCEIVER_RST_GPIO, power);
142
143         return 0;
144 }
145
146 /**
147  * rx51_usb_set_pm_limits - sets omap3-related pm constraints
148  * @dev:        musb's device pointer
149  * @set:        set or clear constraints
150  *
151  * For now we only need mpu wakeup latency mpu frequency, if we
152  * need anything else we just add the logic here and the driver
153  * is already handling what needs to be handled.
154  */
155 static void rx51_usb_set_pm_limits(struct device *dev, bool set)
156 {
157         omap_pm_set_max_mpu_wakeup_lat(dev, set ? 10 : -1);
158         omap_pm_set_min_mpu_freq(dev, set ? 500000000 : 0);
159 }
160
161 static struct musb_board_data rx51_musb_data = {
162         .xceiv_reset    = rx51_xceiv_reset,
163         .xceiv_power    = rx51_xceiv_power,
164         .set_pm_limits  = rx51_usb_set_pm_limits,
165 };
166
167 static void __init rx51_init(void)
168 {
169         rx51_xceiv_init();
170         usb_musb_init(&rx51_musb_data);
171         omap_serial_init();
172         rx51_pm_init();
173         /*
174          * With this early call work around a current clock framework problem
175          * where enabling and then disabling a clock disables a root clock
176          * used by another child clock. In our case this would happen with
177          * hsmmc which is normally initialized before fb.
178          */
179         omap_init_fb();
180         omap_bt_init(&rx51_bt_config);
181 }
182
183 static void __init rx51_map_io(void)
184 {
185         omap_board_config = rx51_config;
186         omap_board_config_size = ARRAY_SIZE(rx51_config);
187         omap2_set_globals_343x();
188         omap2_map_common_io();
189         rx51_video_mem_init();
190 }
191
192 MACHINE_START(NOKIA_RX51, "Nokia RX-51 board")
193         /* Maintainer: Lauri Leukkunen <lauri.leukkunen@nokia.com> */
194         .phys_io        = 0x48000000,
195         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
196         .boot_params    = 0x80000100,
197         .map_io         = rx51_map_io,
198         .init_irq       = rx51_init_irq,
199         .init_machine   = rx51_init,
200         .timer          = &omap_timer,
201 MACHINE_END