Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 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> |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 21 | #include <linux/leds.h> |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame^] | 22 | #include <linux/input.h> |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | #include <linux/io.h> |
| 25 | #include <linux/fsl_devices.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 | |
| 33 | #include <asm/irq.h> |
| 34 | #include <asm/setup.h> |
| 35 | #include <asm/mach-types.h> |
| 36 | #include <asm/mach/arch.h> |
| 37 | #include <asm/mach/time.h> |
| 38 | |
| 39 | #include "devices-imx51.h" |
| 40 | #include "devices.h" |
| 41 | |
Amit Kucheria | 81490fc | 2010-10-07 03:58:25 +0300 | [diff] [blame] | 42 | #define MX51_USB_PLL_DIV_24_MHZ 0x01 |
| 43 | |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 44 | #define EFIKAMX_PCBID0 (2*32 + 16) |
| 45 | #define EFIKAMX_PCBID1 (2*32 + 17) |
| 46 | #define EFIKAMX_PCBID2 (2*32 + 11) |
| 47 | |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 48 | #define EFIKAMX_BLUE_LED (2*32 + 13) |
| 49 | #define EFIKAMX_GREEN_LED (2*32 + 14) |
| 50 | #define EFIKAMX_RED_LED (2*32 + 15) |
| 51 | |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame^] | 52 | #define EFIKAMX_POWER_KEY (1*32 + 31) |
| 53 | |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 54 | /* the pci ids pin have pull up. they're driven low according to board id */ |
| 55 | #define MX51_PAD_PCBID0 IOMUX_PAD(0x518, 0x130, 3, 0x0, 0, PAD_CTL_PUS_100K_UP) |
| 56 | #define MX51_PAD_PCBID1 IOMUX_PAD(0x51C, 0x134, 3, 0x0, 0, PAD_CTL_PUS_100K_UP) |
| 57 | #define MX51_PAD_PCBID2 IOMUX_PAD(0x504, 0x128, 3, 0x0, 0, PAD_CTL_PUS_100K_UP) |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame^] | 58 | #define MX51_PAD_PWRKEY IOMUX_PAD(0x48c, 0x0f8, 1, 0x0, 0, PAD_CTL_PUS_100K_UP | PAD_CTL_PKE) |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 59 | |
Lothar Waßmann | 8f5260c | 2010-10-26 14:28:31 +0200 | [diff] [blame] | 60 | static iomux_v3_cfg_t mx51efikamx_pads[] = { |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 61 | /* UART1 */ |
| 62 | MX51_PAD_UART1_RXD__UART1_RXD, |
| 63 | MX51_PAD_UART1_TXD__UART1_TXD, |
| 64 | MX51_PAD_UART1_RTS__UART1_RTS, |
| 65 | MX51_PAD_UART1_CTS__UART1_CTS, |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 66 | /* board id */ |
| 67 | MX51_PAD_PCBID0, |
| 68 | MX51_PAD_PCBID1, |
| 69 | MX51_PAD_PCBID2, |
Arnaud Patard (Rtp) | a96eb14 | 2010-10-27 14:40:49 +0200 | [diff] [blame] | 70 | |
| 71 | /* SD 1 */ |
| 72 | MX51_PAD_SD1_CMD__SD1_CMD, |
| 73 | MX51_PAD_SD1_CLK__SD1_CLK, |
| 74 | MX51_PAD_SD1_DATA0__SD1_DATA0, |
| 75 | MX51_PAD_SD1_DATA1__SD1_DATA1, |
| 76 | MX51_PAD_SD1_DATA2__SD1_DATA2, |
| 77 | MX51_PAD_SD1_DATA3__SD1_DATA3, |
| 78 | |
| 79 | /* SD 2 */ |
| 80 | MX51_PAD_SD2_CMD__SD2_CMD, |
| 81 | MX51_PAD_SD2_CLK__SD2_CLK, |
| 82 | MX51_PAD_SD2_DATA0__SD2_DATA0, |
| 83 | MX51_PAD_SD2_DATA1__SD2_DATA1, |
| 84 | MX51_PAD_SD2_DATA2__SD2_DATA2, |
| 85 | MX51_PAD_SD2_DATA3__SD2_DATA3, |
| 86 | |
| 87 | /* SD/MMC WP/CD */ |
| 88 | MX51_PAD_GPIO_1_0__ESDHC1_CD, |
| 89 | MX51_PAD_GPIO_1_1__ESDHC1_WP, |
| 90 | MX51_PAD_GPIO_1_7__ESDHC2_WP, |
| 91 | MX51_PAD_GPIO_1_8__ESDHC2_CD, |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 92 | |
| 93 | /* leds */ |
| 94 | MX51_PAD_CSI1_D9__GPIO_3_13, |
| 95 | MX51_PAD_CSI1_VSYNC__GPIO_3_14, |
| 96 | MX51_PAD_CSI1_HSYNC__GPIO_3_15, |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame^] | 97 | |
| 98 | /* power key */ |
| 99 | MX51_PAD_PWRKEY, |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | /* Serial ports */ |
| 103 | #if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE) |
| 104 | static const struct imxuart_platform_data uart_pdata = { |
| 105 | .flags = IMXUART_HAVE_RTSCTS, |
| 106 | }; |
| 107 | |
| 108 | static inline void mxc_init_imx_uart(void) |
| 109 | { |
| 110 | imx51_add_imx_uart(0, &uart_pdata); |
| 111 | imx51_add_imx_uart(1, &uart_pdata); |
| 112 | imx51_add_imx_uart(2, &uart_pdata); |
| 113 | } |
| 114 | #else /* !SERIAL_IMX */ |
| 115 | static inline void mxc_init_imx_uart(void) |
| 116 | { |
| 117 | } |
| 118 | #endif /* SERIAL_IMX */ |
| 119 | |
Amit Kucheria | 81490fc | 2010-10-07 03:58:25 +0300 | [diff] [blame] | 120 | /* This function is board specific as the bit mask for the plldiv will also |
| 121 | * be different for other Freescale SoCs, thus a common bitmask is not |
| 122 | * possible and cannot get place in /plat-mxc/ehci.c. |
| 123 | */ |
| 124 | static int initialize_otg_port(struct platform_device *pdev) |
| 125 | { |
| 126 | u32 v; |
| 127 | void __iomem *usb_base; |
| 128 | void __iomem *usbother_base; |
| 129 | usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K); |
| 130 | usbother_base = (void __iomem *)(usb_base + MX5_USBOTHER_REGS_OFFSET); |
| 131 | |
| 132 | /* Set the PHY clock to 19.2MHz */ |
| 133 | v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET); |
| 134 | v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK; |
| 135 | v |= MX51_USB_PLL_DIV_24_MHZ; |
| 136 | __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET); |
| 137 | iounmap(usb_base); |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static struct mxc_usbh_platform_data dr_utmi_config = { |
| 142 | .init = initialize_otg_port, |
| 143 | .portsc = MXC_EHCI_UTMI_16BIT, |
| 144 | .flags = MXC_EHCI_INTERNAL_PHY, |
| 145 | }; |
| 146 | |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 147 | /* PCBID2 PCBID1 PCBID0 STATE |
| 148 | 1 1 1 ER1:rev1.1 |
| 149 | 1 1 0 ER2:rev1.2 |
| 150 | 1 0 1 ER3:rev1.3 |
| 151 | 1 0 0 ER4:rev1.4 |
| 152 | */ |
| 153 | static void __init mx51_efikamx_board_id(void) |
| 154 | { |
| 155 | int id; |
| 156 | |
| 157 | /* things are taking time to settle */ |
| 158 | msleep(150); |
| 159 | |
| 160 | gpio_request(EFIKAMX_PCBID0, "pcbid0"); |
| 161 | gpio_direction_input(EFIKAMX_PCBID0); |
| 162 | gpio_request(EFIKAMX_PCBID1, "pcbid1"); |
| 163 | gpio_direction_input(EFIKAMX_PCBID1); |
| 164 | gpio_request(EFIKAMX_PCBID2, "pcbid2"); |
| 165 | gpio_direction_input(EFIKAMX_PCBID2); |
| 166 | |
| 167 | id = gpio_get_value(EFIKAMX_PCBID0); |
| 168 | id |= gpio_get_value(EFIKAMX_PCBID1) << 1; |
| 169 | id |= gpio_get_value(EFIKAMX_PCBID2) << 2; |
| 170 | |
| 171 | switch (id) { |
| 172 | case 7: |
| 173 | system_rev = 0x11; |
| 174 | break; |
| 175 | case 6: |
| 176 | system_rev = 0x12; |
| 177 | break; |
| 178 | case 5: |
| 179 | system_rev = 0x13; |
| 180 | break; |
| 181 | case 4: |
| 182 | system_rev = 0x14; |
| 183 | break; |
| 184 | default: |
| 185 | system_rev = 0x10; |
| 186 | break; |
| 187 | } |
| 188 | |
| 189 | if ((system_rev == 0x10) |
| 190 | || (system_rev == 0x12) |
| 191 | || (system_rev == 0x14)) { |
| 192 | printk(KERN_WARNING |
| 193 | "EfikaMX: Unsupported board revision 1.%u!\n", |
| 194 | system_rev & 0xf); |
| 195 | } |
| 196 | } |
| 197 | |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 198 | static struct gpio_led mx51_efikamx_leds[] = { |
| 199 | { |
| 200 | .name = "efikamx:green", |
| 201 | .default_trigger = "default-on", |
| 202 | .gpio = EFIKAMX_GREEN_LED, |
| 203 | }, |
| 204 | { |
| 205 | .name = "efikamx:red", |
| 206 | .default_trigger = "ide-disk", |
| 207 | .gpio = EFIKAMX_RED_LED, |
| 208 | }, |
| 209 | { |
| 210 | .name = "efikamx:blue", |
| 211 | .default_trigger = "mmc0", |
| 212 | .gpio = EFIKAMX_BLUE_LED, |
| 213 | }, |
| 214 | }; |
| 215 | |
| 216 | static struct gpio_led_platform_data mx51_efikamx_leds_data = { |
| 217 | .leds = mx51_efikamx_leds, |
| 218 | .num_leds = ARRAY_SIZE(mx51_efikamx_leds), |
| 219 | }; |
| 220 | |
| 221 | static struct platform_device mx51_efikamx_leds_device = { |
| 222 | .name = "leds-gpio", |
| 223 | .id = -1, |
| 224 | .dev = { |
| 225 | .platform_data = &mx51_efikamx_leds_data, |
| 226 | }, |
| 227 | }; |
| 228 | |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame^] | 229 | static struct gpio_keys_button mx51_efikamx_powerkey[] = { |
| 230 | { |
| 231 | .code = KEY_POWER, |
| 232 | .gpio = EFIKAMX_POWER_KEY, |
| 233 | .type = EV_PWR, |
| 234 | .desc = "Power Button (CM)", |
| 235 | .wakeup = 1, |
| 236 | .debounce_interval = 10, /* ms */ |
| 237 | }, |
| 238 | }; |
| 239 | |
| 240 | static const struct gpio_keys_platform_data mx51_efikamx_powerkey_data __initconst = { |
| 241 | .buttons = mx51_efikamx_powerkey, |
| 242 | .nbuttons = ARRAY_SIZE(mx51_efikamx_powerkey), |
| 243 | }; |
| 244 | |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 245 | static void __init mxc_board_init(void) |
| 246 | { |
| 247 | mxc_iomux_v3_setup_multiple_pads(mx51efikamx_pads, |
| 248 | ARRAY_SIZE(mx51efikamx_pads)); |
Arnaud Patard (Rtp) | f1dd361 | 2010-10-27 14:40:46 +0200 | [diff] [blame] | 249 | mx51_efikamx_board_id(); |
Amit Kucheria | 81490fc | 2010-10-07 03:58:25 +0300 | [diff] [blame] | 250 | mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config); |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 251 | mxc_init_imx_uart(); |
Arnaud Patard (Rtp) | a96eb14 | 2010-10-27 14:40:49 +0200 | [diff] [blame] | 252 | imx51_add_esdhc(0, NULL); |
| 253 | |
| 254 | /* on < 1.2 boards both SD controllers are used */ |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 255 | if (system_rev < 0x12) { |
Arnaud Patard (Rtp) | a96eb14 | 2010-10-27 14:40:49 +0200 | [diff] [blame] | 256 | imx51_add_esdhc(1, NULL); |
Arnaud Patard (Rtp) | 9d2c0ef | 2010-10-27 14:40:51 +0200 | [diff] [blame] | 257 | mx51_efikamx_leds[2].default_trigger = "mmc1"; |
| 258 | } |
| 259 | |
| 260 | platform_device_register(&mx51_efikamx_leds_device); |
Arnaud Patard (Rtp) | fcbd0c5 | 2010-10-27 14:40:52 +0200 | [diff] [blame^] | 261 | imx51_add_gpio_keys(&mx51_efikamx_powerkey_data); |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static void __init mx51_efikamx_timer_init(void) |
| 265 | { |
| 266 | mx51_clocks_init(32768, 24000000, 22579200, 24576000); |
| 267 | } |
| 268 | |
| 269 | static struct sys_timer mxc_timer = { |
| 270 | .init = mx51_efikamx_timer_init, |
| 271 | }; |
| 272 | |
| 273 | MACHINE_START(MX51_EFIKAMX, "Genesi EfikaMX nettop") |
| 274 | /* Maintainer: Amit Kucheria <amit.kucheria@linaro.org> */ |
Amit Kucheria | 088d01b | 2010-10-07 03:58:12 +0300 | [diff] [blame] | 275 | .boot_params = MX51_PHYS_OFFSET + 0x100, |
| 276 | .map_io = mx51_map_io, |
| 277 | .init_irq = mx51_init_irq, |
| 278 | .init_machine = mxc_board_init, |
| 279 | .timer = &mxc_timer, |
| 280 | MACHINE_END |