blob: c08ec63415e57ff9f7a6f9fe25da949e446eaeec [file] [log] [blame]
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +01001/*
2 * based on code from the following
3 * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
4 * Copyright 2009-2010 Pegatron Corporation. All Rights Reserved.
5 * Copyright 2009-2010 Genesi USA, Inc. All Rights Reserved.
6 *
7 * The code contained herein is licensed under the GNU General Public
8 * License. You may obtain a copy of the GNU General Public License
9 * Version 2 or later at the following locations:
10 *
11 * http://www.opensource.org/licenses/gpl-license.html
12 * http://www.gnu.org/copyleft/gpl.html
13 */
14
15#include <linux/init.h>
16#include <linux/platform_device.h>
17#include <linux/i2c.h>
18#include <linux/gpio.h>
19#include <linux/leds.h>
20#include <linux/input.h>
21#include <linux/delay.h>
22#include <linux/io.h>
23#include <linux/fsl_devices.h>
24#include <linux/spi/flash.h>
25#include <linux/spi/spi.h>
26
27#include <mach/common.h>
28#include <mach/hardware.h>
29#include <mach/iomux-mx51.h>
30#include <mach/i2c.h>
31#include <mach/mxc_ehci.h>
32
Arnaud Patard (Rtp)9d72af62011-02-17 15:31:29 +010033#include <linux/usb/otg.h>
34#include <linux/usb/ulpi.h>
35#include <mach/ulpi.h>
36
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +010037#include <asm/irq.h>
38#include <asm/setup.h>
39#include <asm/mach-types.h>
40#include <asm/mach/arch.h>
41#include <asm/mach/time.h>
42
43#include "devices-imx51.h"
44#include "devices.h"
45#include "efika.h"
46
Arnaud Patard (Rtp)9d72af62011-02-17 15:31:29 +010047#define MX51_USB_CTRL_1_OFFSET 0x10
48#define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
49#define MX51_USB_PLL_DIV_19_2_MHZ 0x01
50
51#define EFIKAMX_USB_HUB_RESET IMX_GPIO_NR(1, 5)
52#define EFIKAMX_USBH1_STP IMX_GPIO_NR(1, 27)
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +010053
54#define EFIKAMX_SPI_CS0 IMX_GPIO_NR(4, 24)
55#define EFIKAMX_SPI_CS1 IMX_GPIO_NR(4, 25)
56
57static iomux_v3_cfg_t mx51efika_pads[] = {
58 /* UART1 */
59 MX51_PAD_UART1_RXD__UART1_RXD,
60 MX51_PAD_UART1_TXD__UART1_TXD,
61 MX51_PAD_UART1_RTS__UART1_RTS,
62 MX51_PAD_UART1_CTS__UART1_CTS,
63
64 /* SD 1 */
65 MX51_PAD_SD1_CMD__SD1_CMD,
66 MX51_PAD_SD1_CLK__SD1_CLK,
67 MX51_PAD_SD1_DATA0__SD1_DATA0,
68 MX51_PAD_SD1_DATA1__SD1_DATA1,
69 MX51_PAD_SD1_DATA2__SD1_DATA2,
70 MX51_PAD_SD1_DATA3__SD1_DATA3,
71
72 /* SD 2 */
73 MX51_PAD_SD2_CMD__SD2_CMD,
74 MX51_PAD_SD2_CLK__SD2_CLK,
75 MX51_PAD_SD2_DATA0__SD2_DATA0,
76 MX51_PAD_SD2_DATA1__SD2_DATA1,
77 MX51_PAD_SD2_DATA2__SD2_DATA2,
78 MX51_PAD_SD2_DATA3__SD2_DATA3,
79
80 /* SD/MMC WP/CD */
81 MX51_PAD_GPIO1_0__SD1_CD,
82 MX51_PAD_GPIO1_1__SD1_WP,
83 MX51_PAD_GPIO1_7__SD2_WP,
84 MX51_PAD_GPIO1_8__SD2_CD,
85
86 /* spi */
87 MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI,
88 MX51_PAD_CSPI1_MISO__ECSPI1_MISO,
89 MX51_PAD_CSPI1_SS0__GPIO4_24,
90 MX51_PAD_CSPI1_SS1__GPIO4_25,
91 MX51_PAD_CSPI1_RDY__ECSPI1_RDY,
92 MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK,
Arnaud Patard (Rtp)9d72af62011-02-17 15:31:29 +010093
94 /* USB HOST1 */
95 MX51_PAD_USBH1_CLK__USBH1_CLK,
96 MX51_PAD_USBH1_DIR__USBH1_DIR,
97 MX51_PAD_USBH1_NXT__USBH1_NXT,
98 MX51_PAD_USBH1_DATA0__USBH1_DATA0,
99 MX51_PAD_USBH1_DATA1__USBH1_DATA1,
100 MX51_PAD_USBH1_DATA2__USBH1_DATA2,
101 MX51_PAD_USBH1_DATA3__USBH1_DATA3,
102 MX51_PAD_USBH1_DATA4__USBH1_DATA4,
103 MX51_PAD_USBH1_DATA5__USBH1_DATA5,
104 MX51_PAD_USBH1_DATA6__USBH1_DATA6,
105 MX51_PAD_USBH1_DATA7__USBH1_DATA7,
106
107 /* USB HUB RESET */
108 MX51_PAD_GPIO1_5__GPIO1_5,
109
110 /* WLAN */
111 MX51_PAD_EIM_A22__GPIO2_16,
112 MX51_PAD_EIM_A16__GPIO2_10,
113
114 /* USB PHY RESET */
115 MX51_PAD_EIM_D27__GPIO2_9,
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +0100116};
117
118/* Serial ports */
119static const struct imxuart_platform_data uart_pdata = {
120 .flags = IMXUART_HAVE_RTSCTS,
121};
122
123/* This function is board specific as the bit mask for the plldiv will also
124 * be different for other Freescale SoCs, thus a common bitmask is not
125 * possible and cannot get place in /plat-mxc/ehci.c.
126 */
127static int initialize_otg_port(struct platform_device *pdev)
128{
129 u32 v;
130 void __iomem *usb_base;
131 void __iomem *usbother_base;
132 usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
133 if (!usb_base)
134 return -ENOMEM;
135 usbother_base = (void __iomem *)(usb_base + MX5_USBOTHER_REGS_OFFSET);
136
137 /* Set the PHY clock to 19.2MHz */
138 v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
139 v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
Arnaud Patard (Rtp)9d72af62011-02-17 15:31:29 +0100140 v |= MX51_USB_PLL_DIV_19_2_MHZ;
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +0100141 __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
142 iounmap(usb_base);
143
144 mdelay(10);
145
Arnaud Patard (Rtp)9d72af62011-02-17 15:31:29 +0100146 return mx51_initialize_usb_hw(pdev->id, MXC_EHCI_INTERNAL_PHY);
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +0100147}
148
149static struct mxc_usbh_platform_data dr_utmi_config = {
150 .init = initialize_otg_port,
151 .portsc = MXC_EHCI_UTMI_16BIT,
152};
153
Arnaud Patard (Rtp)9d72af62011-02-17 15:31:29 +0100154static int initialize_usbh1_port(struct platform_device *pdev)
155{
156 iomux_v3_cfg_t usbh1stp = MX51_PAD_USBH1_STP__USBH1_STP;
157 iomux_v3_cfg_t usbh1gpio = MX51_PAD_USBH1_STP__GPIO1_27;
158 u32 v;
159 void __iomem *usb_base;
160 void __iomem *socregs_base;
161
162 mxc_iomux_v3_setup_pad(usbh1gpio);
163 gpio_request(EFIKAMX_USBH1_STP, "usbh1_stp");
164 gpio_direction_output(EFIKAMX_USBH1_STP, 0);
165 msleep(1);
166 gpio_set_value(EFIKAMX_USBH1_STP, 1);
167 msleep(1);
168
169 usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
170 socregs_base = (void __iomem *)(usb_base + MX5_USBOTHER_REGS_OFFSET);
171
172 /* The clock for the USBH1 ULPI port will come externally */
173 /* from the PHY. */
174 v = __raw_readl(socregs_base + MX51_USB_CTRL_1_OFFSET);
175 __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN,
176 socregs_base + MX51_USB_CTRL_1_OFFSET);
177
178 iounmap(usb_base);
179
180 gpio_free(EFIKAMX_USBH1_STP);
181 mxc_iomux_v3_setup_pad(usbh1stp);
182
183 mdelay(10);
184
185 return mx51_initialize_usb_hw(0, MXC_EHCI_ITC_NO_THRESHOLD);
186}
187
188static struct mxc_usbh_platform_data usbh1_config = {
189 .init = initialize_usbh1_port,
190 .portsc = MXC_EHCI_MODE_ULPI,
191};
192
193static void mx51_efika_hubreset(void)
194{
195 gpio_request(EFIKAMX_USB_HUB_RESET, "usb_hub_rst");
196 gpio_direction_output(EFIKAMX_USB_HUB_RESET, 1);
197 msleep(1);
198 gpio_set_value(EFIKAMX_USB_HUB_RESET, 0);
199 msleep(1);
200 gpio_set_value(EFIKAMX_USB_HUB_RESET, 1);
201}
202
203static void __init mx51_efika_usb(void)
204{
205 mx51_efika_hubreset();
206
207 /* pulling it low, means no USB at all... */
208 gpio_request(EFIKA_USB_PHY_RESET, "usb_phy_reset");
209 gpio_direction_output(EFIKA_USB_PHY_RESET, 0);
210 msleep(1);
211 gpio_set_value(EFIKA_USB_PHY_RESET, 1);
212
213 usbh1_config.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
214 ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT |
215 ULPI_OTG_EXTVBUSIND);
216
217 mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
218 mxc_register_device(&mxc_usbh1_device, &usbh1_config);
219}
220
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +0100221static struct mtd_partition mx51_efika_spi_nor_partitions[] = {
222 {
223 .name = "u-boot",
224 .offset = 0,
225 .size = SZ_256K,
226 },
227 {
228 .name = "config",
229 .offset = MTDPART_OFS_APPEND,
230 .size = SZ_64K,
231 },
232};
233
234static struct flash_platform_data mx51_efika_spi_flash_data = {
235 .name = "spi_flash",
236 .parts = mx51_efika_spi_nor_partitions,
237 .nr_parts = ARRAY_SIZE(mx51_efika_spi_nor_partitions),
238 .type = "sst25vf032b",
239};
240
241static struct spi_board_info mx51_efika_spi_board_info[] __initdata = {
242 {
243 .modalias = "m25p80",
244 .max_speed_hz = 25000000,
245 .bus_num = 0,
246 .chip_select = 1,
247 .platform_data = &mx51_efika_spi_flash_data,
248 .irq = -1,
249 },
250};
251
252static int mx51_efika_spi_cs[] = {
253 EFIKAMX_SPI_CS0,
254 EFIKAMX_SPI_CS1,
255};
256
257static const struct spi_imx_master mx51_efika_spi_pdata __initconst = {
258 .chipselect = mx51_efika_spi_cs,
259 .num_chipselect = ARRAY_SIZE(mx51_efika_spi_cs),
260};
261
262void __init efika_board_common_init(void)
263{
264 mxc_iomux_v3_setup_multiple_pads(mx51efika_pads,
265 ARRAY_SIZE(mx51efika_pads));
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +0100266 imx51_add_imx_uart(0, &uart_pdata);
Arnaud Patard (Rtp)9d72af62011-02-17 15:31:29 +0100267 mx51_efika_usb();
Arnaud Patard (Rtp)7ac18a32011-02-17 15:31:28 +0100268 imx51_add_sdhci_esdhc_imx(0, NULL);
269
270 spi_register_board_info(mx51_efika_spi_board_info,
271 ARRAY_SIZE(mx51_efika_spi_board_info));
272 imx51_add_ecspi(0, &mx51_efika_spi_pdata);
273}
274