Staging: hv: mousevsc: Cleanup alloc_input_device()
[zen-stable.git] / arch / arm / mach-mxs / module-tx28.c
blob0fcff47009cf13ff53db9757e58c9dc0cbf5b927
1 /*
2 * Copyright (C) 2010 <LW@KARO-electronics.de>
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 2 as published by the
6 * Free Software Foundation.
7 */
9 #include <linux/delay.h>
10 #include <linux/fec.h>
11 #include <linux/gpio.h>
13 #include <mach/iomux-mx28.h>
14 #include "../devices-mx28.h"
16 #include "module-tx28.h"
18 #define TX28_FEC_PHY_POWER MXS_GPIO_NR(3, 29)
19 #define TX28_FEC_PHY_RESET MXS_GPIO_NR(4, 13)
21 static const iomux_cfg_t tx28_fec_gpio_pads[] __initconst = {
22 /* PHY POWER */
23 MX28_PAD_PWM4__GPIO_3_29 |
24 MXS_PAD_4MA | MXS_PAD_NOPULL | MXS_PAD_3V3,
25 /* PHY RESET */
26 MX28_PAD_ENET0_RX_CLK__GPIO_4_13 |
27 MXS_PAD_4MA | MXS_PAD_NOPULL | MXS_PAD_3V3,
28 /* Mode strap pins 0-2 */
29 MX28_PAD_ENET0_RXD0__GPIO_4_3 |
30 MXS_PAD_8MA | MXS_PAD_PULLUP | MXS_PAD_3V3,
31 MX28_PAD_ENET0_RXD1__GPIO_4_4 |
32 MXS_PAD_8MA | MXS_PAD_PULLUP | MXS_PAD_3V3,
33 MX28_PAD_ENET0_RX_EN__GPIO_4_2 |
34 MXS_PAD_8MA | MXS_PAD_PULLUP | MXS_PAD_3V3,
35 /* nINT */
36 MX28_PAD_ENET0_TX_CLK__GPIO_4_5 |
37 MXS_PAD_4MA | MXS_PAD_NOPULL | MXS_PAD_3V3,
39 MX28_PAD_ENET0_MDC__GPIO_4_0,
40 MX28_PAD_ENET0_MDIO__GPIO_4_1,
41 MX28_PAD_ENET0_TX_EN__GPIO_4_6,
42 MX28_PAD_ENET0_TXD0__GPIO_4_7,
43 MX28_PAD_ENET0_TXD1__GPIO_4_8,
44 MX28_PAD_ENET_CLK__GPIO_4_16,
47 #define FEC_MODE (MXS_PAD_8MA | MXS_PAD_PULLUP | MXS_PAD_3V3)
48 static const iomux_cfg_t tx28_fec0_pads[] __initconst = {
49 MX28_PAD_ENET0_MDC__ENET0_MDC | FEC_MODE,
50 MX28_PAD_ENET0_MDIO__ENET0_MDIO | FEC_MODE,
51 MX28_PAD_ENET0_RX_EN__ENET0_RX_EN | FEC_MODE,
52 MX28_PAD_ENET0_RXD0__ENET0_RXD0 | FEC_MODE,
53 MX28_PAD_ENET0_RXD1__ENET0_RXD1 | FEC_MODE,
54 MX28_PAD_ENET0_TX_EN__ENET0_TX_EN | FEC_MODE,
55 MX28_PAD_ENET0_TXD0__ENET0_TXD0 | FEC_MODE,
56 MX28_PAD_ENET0_TXD1__ENET0_TXD1 | FEC_MODE,
57 MX28_PAD_ENET_CLK__CLKCTRL_ENET | FEC_MODE,
60 static const iomux_cfg_t tx28_fec1_pads[] __initconst = {
61 MX28_PAD_ENET0_RXD2__ENET1_RXD0,
62 MX28_PAD_ENET0_RXD3__ENET1_RXD1,
63 MX28_PAD_ENET0_TXD2__ENET1_TXD0,
64 MX28_PAD_ENET0_TXD3__ENET1_TXD1,
65 MX28_PAD_ENET0_COL__ENET1_TX_EN,
66 MX28_PAD_ENET0_CRS__ENET1_RX_EN,
69 static struct fec_platform_data tx28_fec0_data = {
70 .phy = PHY_INTERFACE_MODE_RMII,
73 static struct fec_platform_data tx28_fec1_data = {
74 .phy = PHY_INTERFACE_MODE_RMII,
77 int __init tx28_add_fec0(void)
79 int i, ret;
81 pr_debug("%s: Switching FEC PHY power off\n", __func__);
82 ret = mxs_iomux_setup_multiple_pads(tx28_fec_gpio_pads,
83 ARRAY_SIZE(tx28_fec_gpio_pads));
84 for (i = 0; i < ARRAY_SIZE(tx28_fec_gpio_pads); i++) {
85 unsigned int gpio = MXS_GPIO_NR(PAD_BANK(tx28_fec_gpio_pads[i]),
86 PAD_PIN(tx28_fec_gpio_pads[i]));
88 ret = gpio_request(gpio, "FEC");
89 if (ret) {
90 pr_err("Failed to request GPIO_%d_%d: %d\n",
91 PAD_BANK(tx28_fec_gpio_pads[i]),
92 PAD_PIN(tx28_fec_gpio_pads[i]), ret);
93 goto free_gpios;
95 ret = gpio_direction_output(gpio, 0);
96 if (ret) {
97 pr_err("Failed to set direction of GPIO_%d_%d to output: %d\n",
98 gpio / 32 + 1, gpio % 32, ret);
99 goto free_gpios;
103 /* Power up fec phy */
104 pr_debug("%s: Switching FEC PHY power on\n", __func__);
105 ret = gpio_direction_output(TX28_FEC_PHY_POWER, 1);
106 if (ret) {
107 pr_err("Failed to power on PHY: %d\n", ret);
108 goto free_gpios;
110 mdelay(26); /* 25ms according to data sheet */
112 /* nINT */
113 gpio_direction_input(MXS_GPIO_NR(4, 5));
114 /* Mode strap pins */
115 gpio_direction_output(MXS_GPIO_NR(4, 2), 1);
116 gpio_direction_output(MXS_GPIO_NR(4, 3), 1);
117 gpio_direction_output(MXS_GPIO_NR(4, 4), 1);
119 udelay(100); /* minimum assertion time for nRST */
121 pr_debug("%s: Deasserting FEC PHY RESET\n", __func__);
122 gpio_set_value(TX28_FEC_PHY_RESET, 1);
124 ret = mxs_iomux_setup_multiple_pads(tx28_fec0_pads,
125 ARRAY_SIZE(tx28_fec0_pads));
126 if (ret) {
127 pr_debug("%s: mxs_iomux_setup_multiple_pads() failed with rc: %d\n",
128 __func__, ret);
129 goto free_gpios;
131 pr_debug("%s: Registering FEC0 device\n", __func__);
132 mx28_add_fec(0, &tx28_fec0_data);
133 return 0;
135 free_gpios:
136 while (--i >= 0) {
137 unsigned int gpio = MXS_GPIO_NR(PAD_BANK(tx28_fec_gpio_pads[i]),
138 PAD_PIN(tx28_fec_gpio_pads[i]));
140 gpio_free(gpio);
143 return ret;
146 int __init tx28_add_fec1(void)
148 int ret;
150 ret = mxs_iomux_setup_multiple_pads(tx28_fec1_pads,
151 ARRAY_SIZE(tx28_fec1_pads));
152 if (ret) {
153 pr_debug("%s: mxs_iomux_setup_multiple_pads() failed with rc: %d\n",
154 __func__, ret);
155 return ret;
157 pr_debug("%s: Registering FEC1 device\n", __func__);
158 mx28_add_fec(1, &tx28_fec1_data);
159 return 0;