efikamx: read board id
[pandora-kernel.git] / arch / arm / mach-mx5 / board-mx51_efikamx.c
1 /*
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>
21 #include <linux/delay.h>
22 #include <linux/io.h>
23 #include <linux/fsl_devices.h>
24
25 #include <mach/common.h>
26 #include <mach/hardware.h>
27 #include <mach/iomux-mx51.h>
28 #include <mach/i2c.h>
29 #include <mach/mxc_ehci.h>
30
31 #include <asm/irq.h>
32 #include <asm/setup.h>
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/time.h>
36
37 #include "devices-imx51.h"
38 #include "devices.h"
39
40 #define MX51_USB_PLL_DIV_24_MHZ 0x01
41
42 #define EFIKAMX_PCBID0          (2*32 + 16)
43 #define EFIKAMX_PCBID1          (2*32 + 17)
44 #define EFIKAMX_PCBID2          (2*32 + 11)
45
46 /* the pci ids pin have pull up. they're driven low according to board id */
47 #define MX51_PAD_PCBID0 IOMUX_PAD(0x518, 0x130, 3, 0x0,   0, PAD_CTL_PUS_100K_UP)
48 #define MX51_PAD_PCBID1 IOMUX_PAD(0x51C, 0x134, 3, 0x0,   0, PAD_CTL_PUS_100K_UP)
49 #define MX51_PAD_PCBID2 IOMUX_PAD(0x504, 0x128, 3, 0x0,   0, PAD_CTL_PUS_100K_UP)
50
51 static iomux_v3_cfg_t mx51efikamx_pads[] = {
52         /* UART1 */
53         MX51_PAD_UART1_RXD__UART1_RXD,
54         MX51_PAD_UART1_TXD__UART1_TXD,
55         MX51_PAD_UART1_RTS__UART1_RTS,
56         MX51_PAD_UART1_CTS__UART1_CTS,
57         /* board id */
58         MX51_PAD_PCBID0,
59         MX51_PAD_PCBID1,
60         MX51_PAD_PCBID2,
61 };
62
63 /* Serial ports */
64 #if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE)
65 static const struct imxuart_platform_data uart_pdata = {
66         .flags = IMXUART_HAVE_RTSCTS,
67 };
68
69 static inline void mxc_init_imx_uart(void)
70 {
71         imx51_add_imx_uart(0, &uart_pdata);
72         imx51_add_imx_uart(1, &uart_pdata);
73         imx51_add_imx_uart(2, &uart_pdata);
74 }
75 #else /* !SERIAL_IMX */
76 static inline void mxc_init_imx_uart(void)
77 {
78 }
79 #endif /* SERIAL_IMX */
80
81 /* This function is board specific as the bit mask for the plldiv will also
82  * be different for other Freescale SoCs, thus a common bitmask is not
83  * possible and cannot get place in /plat-mxc/ehci.c.
84  */
85 static int initialize_otg_port(struct platform_device *pdev)
86 {
87         u32 v;
88         void __iomem *usb_base;
89         void __iomem *usbother_base;
90         usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
91         usbother_base = (void __iomem *)(usb_base + MX5_USBOTHER_REGS_OFFSET);
92
93         /* Set the PHY clock to 19.2MHz */
94         v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
95         v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
96         v |= MX51_USB_PLL_DIV_24_MHZ;
97         __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
98         iounmap(usb_base);
99         return 0;
100 }
101
102 static struct mxc_usbh_platform_data dr_utmi_config = {
103         .init   = initialize_otg_port,
104         .portsc = MXC_EHCI_UTMI_16BIT,
105         .flags  = MXC_EHCI_INTERNAL_PHY,
106 };
107
108 /*   PCBID2  PCBID1 PCBID0  STATE
109         1       1      1    ER1:rev1.1
110         1       1      0    ER2:rev1.2
111         1       0      1    ER3:rev1.3
112         1       0      0    ER4:rev1.4
113 */
114 static void __init mx51_efikamx_board_id(void)
115 {
116         int id;
117
118         /* things are taking time to settle */
119         msleep(150);
120
121         gpio_request(EFIKAMX_PCBID0, "pcbid0");
122         gpio_direction_input(EFIKAMX_PCBID0);
123         gpio_request(EFIKAMX_PCBID1, "pcbid1");
124         gpio_direction_input(EFIKAMX_PCBID1);
125         gpio_request(EFIKAMX_PCBID2, "pcbid2");
126         gpio_direction_input(EFIKAMX_PCBID2);
127
128         id = gpio_get_value(EFIKAMX_PCBID0);
129         id |= gpio_get_value(EFIKAMX_PCBID1) << 1;
130         id |= gpio_get_value(EFIKAMX_PCBID2) << 2;
131
132         switch (id) {
133         case 7:
134                 system_rev = 0x11;
135                 break;
136         case 6:
137                 system_rev = 0x12;
138                 break;
139         case 5:
140                 system_rev = 0x13;
141                 break;
142         case 4:
143                 system_rev = 0x14;
144                 break;
145         default:
146                 system_rev = 0x10;
147                 break;
148         }
149
150         if ((system_rev == 0x10)
151                 || (system_rev == 0x12)
152                 || (system_rev == 0x14)) {
153                 printk(KERN_WARNING
154                         "EfikaMX: Unsupported board revision 1.%u!\n",
155                         system_rev & 0xf);
156         }
157 }
158
159 static void __init mxc_board_init(void)
160 {
161         mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads,
162                                         ARRAY_SIZE(mx51efikamx_pads));
163         mx51_efikamx_board_id();
164         mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
165         mxc_init_imx_uart();
166 }
167
168 static void __init mx51_efikamx_timer_init(void)
169 {
170         mx51_clocks_init(32768, 24000000, 22579200, 24576000);
171 }
172
173 static struct sys_timer mxc_timer = {
174         .init   = mx51_efikamx_timer_init,
175 };
176
177 MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop")
178         /* Maintainer: Amit Kucheria <amit.kucheria@linaro.org> */
179         .boot_params = MX51_PHYS_OFFSET + 0x100,
180         .map_io = mx51_map_io,
181         .init_irq = mx51_init_irq,
182         .init_machine =  mxc_board_init,
183         .timer = &mxc_timer,
184 MACHINE_END