blob: c4094fa5794f6dbd0da750f5895771adf3ace4cb [file] [log] [blame]
Amit Kucheria088d01b2010-10-07 03:58:12 +03001/*
2 * Copyright (C) 2010 Linaro Limited
3 *
4 * based on code from the following
5 * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
6 * Copyright 2009-2010 Pegatron Corporation. All Rights Reserved.
7 * Copyright 2009-2010 Genesi USA, Inc. All Rights Reserved.
8 *
9 * The code contained herein is licensed under the GNU General Public
10 * License. You may obtain a copy of the GNU General Public License
11 * Version 2 or later at the following locations:
12 *
13 * http://www.opensource.org/licenses/gpl-license.html
14 * http://www.gnu.org/copyleft/gpl.html
15 */
16
17#include <linux/init.h>
18#include <linux/platform_device.h>
19#include <linux/i2c.h>
20#include <linux/gpio.h>
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +020021#include <linux/leds.h>
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020022#include <linux/input.h>
Amit Kucheria088d01b2010-10-07 03:58:12 +030023#include <linux/delay.h>
24#include <linux/io.h>
25#include <linux/fsl_devices.h>
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +020026#include <linux/spi/flash.h>
27#include <linux/spi/spi.h>
Amit Kucheria088d01b2010-10-07 03:58:12 +030028
29#include <mach/common.h>
30#include <mach/hardware.h>
31#include <mach/iomux-mx51.h>
32#include <mach/i2c.h>
33#include <mach/mxc_ehci.h>
34
35#include <asm/irq.h>
36#include <asm/setup.h>
37#include <asm/mach-types.h>
38#include <asm/mach/arch.h>
39#include <asm/mach/time.h>
40
41#include "devices-imx51.h"
42#include "devices.h"
43
Amit Kucheria81490fc2010-10-07 03:58:25 +030044#define MX51_USB_PLL_DIV_24_MHZ 0x01
45
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010046#define EFIKAMX_PCBID0 IMX_GPIO_NR(3, 16)
47#define EFIKAMX_PCBID1 IMX_GPIO_NR(3, 17)
48#define EFIKAMX_PCBID2 IMX_GPIO_NR(3, 11)
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020049
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010050#define EFIKAMX_BLUE_LED IMX_GPIO_NR(3, 13)
51#define EFIKAMX_GREEN_LED IMX_GPIO_NR(3, 14)
52#define EFIKAMX_RED_LED IMX_GPIO_NR(3, 15)
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +020053
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010054#define EFIKAMX_POWER_KEY IMX_GPIO_NR(2, 31)
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020055
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010056#define EFIKAMX_SPI_CS0 IMX_GPIO_NR(4, 24)
57#define EFIKAMX_SPI_CS1 IMX_GPIO_NR(4, 25)
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +020058
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020059/* board 1.1 doesn't have same reset gpio */
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010060#define EFIKAMX_RESET1_1 IMX_GPIO_NR(3, 2)
61#define EFIKAMX_RESET IMX_GPIO_NR(1, 4)
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020062
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020063/* the pci ids pin have pull up. they're driven low according to board id */
64#define MX51_PAD_PCBID0 IOMUX_PAD(0x518, 0x130, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
65#define MX51_PAD_PCBID1 IOMUX_PAD(0x51C, 0x134, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
66#define MX51_PAD_PCBID2 IOMUX_PAD(0x504, 0x128, 3, 0x0, 0, PAD_CTL_PUS_100K_UP)
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +020067#define MX51_PAD_PWRKEY IOMUX_PAD(0x48c, 0x0f8, 1, 0x0, 0, PAD_CTL_PUS_100K_UP | PAD_CTL_PKE)
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020068
Lothar Waßmann8f5260c2010-10-26 14:28:31 +020069static iomux_v3_cfg_t mx51efikamx_pads[] = {
Amit Kucheria088d01b2010-10-07 03:58:12 +030070 /* UART1 */
71 MX51_PAD_UART1_RXD__UART1_RXD,
72 MX51_PAD_UART1_TXD__UART1_TXD,
73 MX51_PAD_UART1_RTS__UART1_RTS,
74 MX51_PAD_UART1_CTS__UART1_CTS,
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +020075 /* board id */
76 MX51_PAD_PCBID0,
77 MX51_PAD_PCBID1,
78 MX51_PAD_PCBID2,
Arnaud Patard (Rtp)a96eb142010-10-27 14:40:49 +020079
80 /* SD 1 */
81 MX51_PAD_SD1_CMD__SD1_CMD,
82 MX51_PAD_SD1_CLK__SD1_CLK,
83 MX51_PAD_SD1_DATA0__SD1_DATA0,
84 MX51_PAD_SD1_DATA1__SD1_DATA1,
85 MX51_PAD_SD1_DATA2__SD1_DATA2,
86 MX51_PAD_SD1_DATA3__SD1_DATA3,
87
88 /* SD 2 */
89 MX51_PAD_SD2_CMD__SD2_CMD,
90 MX51_PAD_SD2_CLK__SD2_CLK,
91 MX51_PAD_SD2_DATA0__SD2_DATA0,
92 MX51_PAD_SD2_DATA1__SD2_DATA1,
93 MX51_PAD_SD2_DATA2__SD2_DATA2,
94 MX51_PAD_SD2_DATA3__SD2_DATA3,
95
96 /* SD/MMC WP/CD */
Sascha Haueree1ae4d2010-12-15 09:56:35 +010097 MX51_PAD_GPIO1_0__SD1_CD,
98 MX51_PAD_GPIO1_1__SD1_WP,
99 MX51_PAD_GPIO1_7__SD2_WP,
100 MX51_PAD_GPIO1_8__SD2_CD,
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200101
102 /* leds */
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100103 MX51_PAD_CSI1_D9__GPIO3_13,
104 MX51_PAD_CSI1_VSYNC__GPIO3_14,
105 MX51_PAD_CSI1_HSYNC__GPIO3_15,
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +0200106
107 /* power key */
108 MX51_PAD_PWRKEY,
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +0200109
110 /* spi */
111 MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI,
112 MX51_PAD_CSPI1_MISO__ECSPI1_MISO,
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100113 MX51_PAD_CSPI1_SS0__GPIO4_24,
114 MX51_PAD_CSPI1_SS1__GPIO4_25,
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +0200115 MX51_PAD_CSPI1_RDY__ECSPI1_RDY,
116 MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK,
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +0200117
118 /* reset */
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100119 MX51_PAD_DI1_PIN13__GPIO3_2,
120 MX51_PAD_GPIO1_4__GPIO1_4,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300121};
122
123/* Serial ports */
Amit Kucheria088d01b2010-10-07 03:58:12 +0300124static const struct imxuart_platform_data uart_pdata = {
125 .flags = IMXUART_HAVE_RTSCTS,
126};
127
Amit Kucheria81490fc2010-10-07 03:58:25 +0300128/* This function is board specific as the bit mask for the plldiv will also
129 * be different for other Freescale SoCs, thus a common bitmask is not
130 * possible and cannot get place in /plat-mxc/ehci.c.
131 */
132static int initialize_otg_port(struct platform_device *pdev)
133{
134 u32 v;
135 void __iomem *usb_base;
136 void __iomem *usbother_base;
137 usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
Fabio Estevam28a4f902010-12-13 10:47:05 -0200138 if (!usb_base)
139 return -ENOMEM;
Amit Kucheria81490fc2010-10-07 03:58:25 +0300140 usbother_base = (void __iomem *)(usb_base + MX5_USBOTHER_REGS_OFFSET);
141
142 /* Set the PHY clock to 19.2MHz */
143 v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
144 v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
145 v |= MX51_USB_PLL_DIV_24_MHZ;
146 __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
147 iounmap(usb_base);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100148
149 mdelay(10);
150
151 return mx51_initialize_usb_hw(0, MXC_EHCI_INTERNAL_PHY);
Amit Kucheria81490fc2010-10-07 03:58:25 +0300152}
153
154static struct mxc_usbh_platform_data dr_utmi_config = {
155 .init = initialize_otg_port,
156 .portsc = MXC_EHCI_UTMI_16BIT,
Amit Kucheria81490fc2010-10-07 03:58:25 +0300157};
158
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +0200159/* PCBID2 PCBID1 PCBID0 STATE
160 1 1 1 ER1:rev1.1
161 1 1 0 ER2:rev1.2
162 1 0 1 ER3:rev1.3
163 1 0 0 ER4:rev1.4
164*/
165static void __init mx51_efikamx_board_id(void)
166{
167 int id;
168
169 /* things are taking time to settle */
170 msleep(150);
171
172 gpio_request(EFIKAMX_PCBID0, "pcbid0");
173 gpio_direction_input(EFIKAMX_PCBID0);
174 gpio_request(EFIKAMX_PCBID1, "pcbid1");
175 gpio_direction_input(EFIKAMX_PCBID1);
176 gpio_request(EFIKAMX_PCBID2, "pcbid2");
177 gpio_direction_input(EFIKAMX_PCBID2);
178
179 id = gpio_get_value(EFIKAMX_PCBID0);
180 id |= gpio_get_value(EFIKAMX_PCBID1) << 1;
181 id |= gpio_get_value(EFIKAMX_PCBID2) << 2;
182
183 switch (id) {
184 case 7:
185 system_rev = 0x11;
186 break;
187 case 6:
188 system_rev = 0x12;
189 break;
190 case 5:
191 system_rev = 0x13;
192 break;
193 case 4:
194 system_rev = 0x14;
195 break;
196 default:
197 system_rev = 0x10;
198 break;
199 }
200
201 if ((system_rev == 0x10)
202 || (system_rev == 0x12)
203 || (system_rev == 0x14)) {
204 printk(KERN_WARNING
205 "EfikaMX: Unsupported board revision 1.%u!\n",
206 system_rev & 0xf);
207 }
208}
209
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200210static struct gpio_led mx51_efikamx_leds[] = {
211 {
212 .name = "efikamx:green",
213 .default_trigger = "default-on",
214 .gpio = EFIKAMX_GREEN_LED,
215 },
216 {
217 .name = "efikamx:red",
218 .default_trigger = "ide-disk",
219 .gpio = EFIKAMX_RED_LED,
220 },
221 {
222 .name = "efikamx:blue",
223 .default_trigger = "mmc0",
224 .gpio = EFIKAMX_BLUE_LED,
225 },
226};
227
228static struct gpio_led_platform_data mx51_efikamx_leds_data = {
229 .leds = mx51_efikamx_leds,
230 .num_leds = ARRAY_SIZE(mx51_efikamx_leds),
231};
232
233static struct platform_device mx51_efikamx_leds_device = {
234 .name = "leds-gpio",
235 .id = -1,
236 .dev = {
237 .platform_data = &mx51_efikamx_leds_data,
238 },
239};
240
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +0200241static struct gpio_keys_button mx51_efikamx_powerkey[] = {
242 {
243 .code = KEY_POWER,
244 .gpio = EFIKAMX_POWER_KEY,
245 .type = EV_PWR,
246 .desc = "Power Button (CM)",
247 .wakeup = 1,
248 .debounce_interval = 10, /* ms */
249 },
250};
251
252static const struct gpio_keys_platform_data mx51_efikamx_powerkey_data __initconst = {
253 .buttons = mx51_efikamx_powerkey,
254 .nbuttons = ARRAY_SIZE(mx51_efikamx_powerkey),
255};
256
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +0200257static struct mtd_partition mx51_efikamx_spi_nor_partitions[] = {
258 {
259 .name = "u-boot",
260 .offset = 0,
261 .size = SZ_256K,
262 },
263 {
264 .name = "config",
265 .offset = MTDPART_OFS_APPEND,
266 .size = SZ_64K,
267 },
268};
269
270static struct flash_platform_data mx51_efikamx_spi_flash_data = {
271 .name = "spi_flash",
272 .parts = mx51_efikamx_spi_nor_partitions,
273 .nr_parts = ARRAY_SIZE(mx51_efikamx_spi_nor_partitions),
274 .type = "sst25vf032b",
275};
276
277static struct spi_board_info mx51_efikamx_spi_board_info[] __initdata = {
278 {
279 .modalias = "m25p80",
280 .max_speed_hz = 25000000,
281 .bus_num = 0,
282 .chip_select = 1,
283 .platform_data = &mx51_efikamx_spi_flash_data,
284 .irq = -1,
285 },
286};
287
288static int mx51_efikamx_spi_cs[] = {
289 EFIKAMX_SPI_CS0,
290 EFIKAMX_SPI_CS1,
291};
292
293static const struct spi_imx_master mx51_efikamx_spi_pdata __initconst = {
294 .chipselect = mx51_efikamx_spi_cs,
295 .num_chipselect = ARRAY_SIZE(mx51_efikamx_spi_cs),
296};
297
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +0200298void mx51_efikamx_reset(void)
299{
300 if (system_rev == 0x11)
301 gpio_direction_output(EFIKAMX_RESET1_1, 0);
302 else
303 gpio_direction_output(EFIKAMX_RESET, 0);
304}
305
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100306static void __init mx51_efikamx_init(void)
Amit Kucheria088d01b2010-10-07 03:58:12 +0300307{
308 mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads,
309 ARRAY_SIZE(mx51efikamx_pads));
Arnaud Patard (Rtp)f1dd3612010-10-27 14:40:46 +0200310 mx51_efikamx_board_id();
Amit Kucheria81490fc2010-10-07 03:58:25 +0300311 mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
Sascha Hauer53cdd302011-01-14 11:34:33 +0100312 imx51_add_imx_uart(0, &uart_pdata);
313 imx51_add_imx_uart(1, &uart_pdata);
314 imx51_add_imx_uart(2, &uart_pdata);
Arnaud Patard (Rtp)0ef51952010-11-26 15:27:53 +0100315 imx51_add_sdhci_esdhc_imx(0, NULL);
Arnaud Patard (Rtp)a96eb142010-10-27 14:40:49 +0200316
317 /* on < 1.2 boards both SD controllers are used */
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200318 if (system_rev < 0x12) {
Arnaud Patard (Rtp)0ef51952010-11-26 15:27:53 +0100319 imx51_add_sdhci_esdhc_imx(1, NULL);
Arnaud Patard (Rtp)9d2c0ef2010-10-27 14:40:51 +0200320 mx51_efikamx_leds[2].default_trigger = "mmc1";
321 }
322
323 platform_device_register(&mx51_efikamx_leds_device);
Arnaud Patard (Rtp)fcbd0c52010-10-27 14:40:52 +0200324 imx51_add_gpio_keys(&mx51_efikamx_powerkey_data);
Arnaud Patard (Rtp)c6e34a42010-10-27 14:40:54 +0200325
326 spi_register_board_info(mx51_efikamx_spi_board_info,
327 ARRAY_SIZE(mx51_efikamx_spi_board_info));
328 imx51_add_ecspi(0, &mx51_efikamx_spi_pdata);
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +0200329
330 if (system_rev == 0x11) {
331 gpio_request(EFIKAMX_RESET1_1, "reset");
332 gpio_direction_output(EFIKAMX_RESET1_1, 1);
333 } else {
334 gpio_request(EFIKAMX_RESET, "reset");
335 gpio_direction_output(EFIKAMX_RESET, 1);
336 }
Amit Kucheria088d01b2010-10-07 03:58:12 +0300337}
338
339static void __init mx51_efikamx_timer_init(void)
340{
341 mx51_clocks_init(32768, 24000000, 22579200, 24576000);
342}
343
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100344static struct sys_timer mx51_efikamx_timer = {
345 .init = mx51_efikamx_timer_init,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300346};
347
348MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop")
349 /* Maintainer: Amit Kucheria <amit.kucheria@linaro.org> */
Amit Kucheria088d01b2010-10-07 03:58:12 +0300350 .boot_params = MX51_PHYS_OFFSET + 0x100,
351 .map_io = mx51_map_io,
Uwe Kleine-Königab130422011-02-07 16:35:21 +0100352 .init_early = imx51_init_early,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300353 .init_irq = mx51_init_irq,
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100354 .timer = &mx51_efikamx_timer,
355 .init_machine = mx51_efikamx_init,
Amit Kucheria088d01b2010-10-07 03:58:12 +0300356MACHINE_END