]>
Commit | Line | Data |
---|---|---|
c942fddf | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
e00f0b4a VL |
2 | /* |
3 | * Copyright (C) 2009 Valentin Longchamp, EPFL Mobots group | |
e00f0b4a VL |
4 | */ |
5 | ||
04ea3c80 | 6 | #include <linux/delay.h> |
45b131a7 | 7 | #include <linux/gpio.h> |
e00f0b4a | 8 | #include <linux/init.h> |
45b131a7 | 9 | #include <linux/interrupt.h> |
04ea3c80 | 10 | #include <linux/i2c.h> |
33c4d919 | 11 | #include <linux/spi/spi.h> |
5a0e3ad6 | 12 | #include <linux/slab.h> |
e00f0b4a | 13 | #include <linux/platform_device.h> |
220bbcea | 14 | #include <linux/types.h> |
e00f0b4a | 15 | |
d67d1075 VL |
16 | #include <linux/usb/otg.h> |
17 | ||
fa5f66c9 | 18 | #include "board-mx31moboard.h" |
e3372474 | 19 | #include "common.h" |
6a697e3d | 20 | #include "devices-imx31.h" |
641dfe8b | 21 | #include "ehci.h" |
50f2de61 | 22 | #include "hardware.h" |
267dd34c | 23 | #include "iomux-mx3.h" |
39ef6340 | 24 | #include "ulpi.h" |
e00f0b4a | 25 | |
56c7a45b VL |
26 | static unsigned int marxbot_pins[] = { |
27 | /* SDHC2 */ | |
28 | MX31_PIN_PC_PWRON__SD2_DATA3, MX31_PIN_PC_VS1__SD2_DATA2, | |
29 | MX31_PIN_PC_READY__SD2_DATA1, MX31_PIN_PC_WAIT_B__SD2_DATA0, | |
30 | MX31_PIN_PC_CD2_B__SD2_CLK, MX31_PIN_PC_CD1_B__SD2_CMD, | |
31 | MX31_PIN_ATA_DIOR__GPIO3_28, MX31_PIN_ATA_DIOW__GPIO3_29, | |
2718c15c VL |
32 | /* dsPIC resets */ |
33 | MX31_PIN_STXD5__GPIO1_21, MX31_PIN_SRXD5__GPIO1_22, | |
10949fff VL |
34 | /*battery detection */ |
35 | MX31_PIN_LCS0__GPIO3_23, | |
d67d1075 VL |
36 | /* USB H1 */ |
37 | MX31_PIN_CSPI1_MISO__USBH1_RXDP, MX31_PIN_CSPI1_MOSI__USBH1_RXDM, | |
38 | MX31_PIN_CSPI1_SS0__USBH1_TXDM, MX31_PIN_CSPI1_SS1__USBH1_TXDP, | |
39 | MX31_PIN_CSPI1_SS2__USBH1_RCV, MX31_PIN_CSPI1_SCLK__USBH1_OEB, | |
40 | MX31_PIN_CSPI1_SPI_RDY__USBH1_FS, MX31_PIN_SFS6__USBH1_SUSPEND, | |
41 | MX31_PIN_NFRE_B__GPIO1_11, MX31_PIN_NFALE__GPIO1_12, | |
e335c75c VL |
42 | /* SEL */ |
43 | MX31_PIN_DTR_DCE1__GPIO2_8, MX31_PIN_DSR_DCE1__GPIO2_9, | |
44 | MX31_PIN_RI_DCE1__GPIO2_10, MX31_PIN_DCD_DCE1__GPIO2_11, | |
56c7a45b VL |
45 | }; |
46 | ||
45b131a7 VL |
47 | #define SDHC2_CD IOMUX_TO_GPIO(MX31_PIN_ATA_DIOR) |
48 | #define SDHC2_WP IOMUX_TO_GPIO(MX31_PIN_ATA_DIOW) | |
49 | ||
50 | static int marxbot_sdhc2_get_ro(struct device *dev) | |
51 | { | |
563abb4b | 52 | return !gpio_get_value(SDHC2_WP); |
45b131a7 VL |
53 | } |
54 | ||
55 | static int marxbot_sdhc2_init(struct device *dev, irq_handler_t detect_irq, | |
56 | void *data) | |
57 | { | |
4f163eb8 SH |
58 | int ret; |
59 | ||
60 | ret = gpio_request(SDHC2_CD, "sdhc-detect"); | |
61 | if (ret) | |
62 | return ret; | |
63 | ||
64 | gpio_direction_input(SDHC2_CD); | |
65 | ||
66 | ret = gpio_request(SDHC2_WP, "sdhc-wp"); | |
67 | if (ret) | |
68 | goto err_gpio_free; | |
69 | gpio_direction_input(SDHC2_WP); | |
70 | ||
71 | ret = request_irq(gpio_to_irq(SDHC2_CD), detect_irq, | |
45b131a7 VL |
72 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
73 | "sdhc2-card-detect", data); | |
4f163eb8 SH |
74 | if (ret) |
75 | goto err_gpio_free_2; | |
76 | ||
77 | return 0; | |
78 | ||
79 | err_gpio_free_2: | |
80 | gpio_free(SDHC2_WP); | |
81 | err_gpio_free: | |
82 | gpio_free(SDHC2_CD); | |
83 | ||
84 | return ret; | |
45b131a7 VL |
85 | } |
86 | ||
87 | static void marxbot_sdhc2_exit(struct device *dev, void *data) | |
88 | { | |
89 | free_irq(gpio_to_irq(SDHC2_CD), data); | |
4f163eb8 SH |
90 | gpio_free(SDHC2_WP); |
91 | gpio_free(SDHC2_CD); | |
45b131a7 VL |
92 | } |
93 | ||
6a697e3d | 94 | static const struct imxmmc_platform_data sdhc2_pdata __initconst = { |
45b131a7 VL |
95 | .get_ro = marxbot_sdhc2_get_ro, |
96 | .init = marxbot_sdhc2_init, | |
97 | .exit = marxbot_sdhc2_exit, | |
98 | }; | |
99 | ||
2718c15c VL |
100 | #define TRSLAT_RST_B IOMUX_TO_GPIO(MX31_PIN_STXD5) |
101 | #define DSPICS_RST_B IOMUX_TO_GPIO(MX31_PIN_SRXD5) | |
102 | ||
103 | static void dspics_resets_init(void) | |
104 | { | |
105 | if (!gpio_request(TRSLAT_RST_B, "translator-rst")) { | |
f8594c28 | 106 | gpio_direction_output(TRSLAT_RST_B, 0); |
2718c15c VL |
107 | gpio_export(TRSLAT_RST_B, false); |
108 | } | |
109 | ||
110 | if (!gpio_request(DSPICS_RST_B, "dspics-rst")) { | |
f8594c28 | 111 | gpio_direction_output(DSPICS_RST_B, 0); |
2718c15c VL |
112 | gpio_export(DSPICS_RST_B, false); |
113 | } | |
114 | } | |
115 | ||
33c4d919 VL |
116 | static struct spi_board_info marxbot_spi_board_info[] __initdata = { |
117 | { | |
118 | .modalias = "spidev", | |
119 | .max_speed_hz = 300000, | |
120 | .bus_num = 1, | |
121 | .chip_select = 1, /* according spi1_cs[] ! */ | |
122 | }, | |
123 | }; | |
124 | ||
e335c75c VL |
125 | #define SEL0 IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1) |
126 | #define SEL1 IOMUX_TO_GPIO(MX31_PIN_DSR_DCE1) | |
127 | #define SEL2 IOMUX_TO_GPIO(MX31_PIN_RI_DCE1) | |
128 | #define SEL3 IOMUX_TO_GPIO(MX31_PIN_DCD_DCE1) | |
129 | ||
130 | static void marxbot_init_sel_gpios(void) | |
131 | { | |
132 | if (!gpio_request(SEL0, "sel0")) { | |
133 | gpio_direction_input(SEL0); | |
134 | gpio_export(SEL0, true); | |
135 | } | |
136 | ||
137 | if (!gpio_request(SEL1, "sel1")) { | |
138 | gpio_direction_input(SEL1); | |
139 | gpio_export(SEL1, true); | |
140 | } | |
141 | ||
142 | if (!gpio_request(SEL2, "sel2")) { | |
143 | gpio_direction_input(SEL2); | |
144 | gpio_export(SEL2, true); | |
145 | } | |
146 | ||
147 | if (!gpio_request(SEL3, "sel3")) { | |
148 | gpio_direction_input(SEL3); | |
149 | gpio_export(SEL3, true); | |
150 | } | |
151 | } | |
152 | ||
d67d1075 VL |
153 | #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \ |
154 | PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU) | |
155 | ||
156 | static int marxbot_usbh1_hw_init(struct platform_device *pdev) | |
157 | { | |
158 | mxc_iomux_set_gpr(MUX_PGP_USB_SUSPEND, true); | |
159 | ||
160 | mxc_iomux_set_pad(MX31_PIN_CSPI1_MISO, USB_PAD_CFG); | |
161 | mxc_iomux_set_pad(MX31_PIN_CSPI1_MOSI, USB_PAD_CFG); | |
162 | mxc_iomux_set_pad(MX31_PIN_CSPI1_SS0, USB_PAD_CFG); | |
163 | mxc_iomux_set_pad(MX31_PIN_CSPI1_SS1, USB_PAD_CFG); | |
164 | mxc_iomux_set_pad(MX31_PIN_CSPI1_SS2, USB_PAD_CFG); | |
165 | mxc_iomux_set_pad(MX31_PIN_CSPI1_SCLK, USB_PAD_CFG); | |
166 | mxc_iomux_set_pad(MX31_PIN_CSPI1_SPI_RDY, USB_PAD_CFG); | |
167 | mxc_iomux_set_pad(MX31_PIN_SFS6, USB_PAD_CFG); | |
168 | ||
4bd597b6 SH |
169 | mdelay(10); |
170 | ||
171 | return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED | | |
172 | MXC_EHCI_INTERFACE_SINGLE_UNI); | |
d67d1075 VL |
173 | } |
174 | ||
175 | #define USBH1_VBUSEN_B IOMUX_TO_GPIO(MX31_PIN_NFRE_B) | |
176 | #define USBH1_MODE IOMUX_TO_GPIO(MX31_PIN_NFALE) | |
177 | ||
86753811 | 178 | static int marxbot_isp1105_init(struct usb_phy *otg) |
d67d1075 VL |
179 | { |
180 | int ret = gpio_request(USBH1_MODE, "usbh1-mode"); | |
181 | if (ret) | |
182 | return ret; | |
183 | /* single ended */ | |
184 | gpio_direction_output(USBH1_MODE, 0); | |
185 | ||
186 | ret = gpio_request(USBH1_VBUSEN_B, "usbh1-vbusen"); | |
187 | if (ret) { | |
188 | gpio_free(USBH1_MODE); | |
189 | return ret; | |
190 | } | |
191 | gpio_direction_output(USBH1_VBUSEN_B, 1); | |
192 | ||
193 | return 0; | |
194 | } | |
195 | ||
196 | ||
76eb57ec | 197 | static int marxbot_isp1105_set_vbus(struct usb_otg *otg, bool on) |
d67d1075 VL |
198 | { |
199 | if (on) | |
200 | gpio_set_value(USBH1_VBUSEN_B, 0); | |
201 | else | |
202 | gpio_set_value(USBH1_VBUSEN_B, 1); | |
203 | ||
204 | return 0; | |
205 | } | |
206 | ||
2d58de28 | 207 | static struct mxc_usbh_platform_data usbh1_pdata __initdata = { |
d67d1075 VL |
208 | .init = marxbot_usbh1_hw_init, |
209 | .portsc = MXC_EHCI_MODE_UTMI | MXC_EHCI_SERIAL, | |
d67d1075 VL |
210 | }; |
211 | ||
212 | static int __init marxbot_usbh1_init(void) | |
213 | { | |
76eb57ec | 214 | struct usb_phy *phy; |
2d58de28 | 215 | struct platform_device *pdev; |
d67d1075 | 216 | |
76eb57ec HK |
217 | phy = kzalloc(sizeof(*phy), GFP_KERNEL); |
218 | if (!phy) | |
d67d1075 VL |
219 | return -ENOMEM; |
220 | ||
76eb57ec HK |
221 | phy->otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); |
222 | if (!phy->otg) { | |
223 | kfree(phy); | |
224 | return -ENOMEM; | |
225 | } | |
226 | ||
227 | phy->label = "ISP1105"; | |
228 | phy->init = marxbot_isp1105_init; | |
229 | phy->otg->set_vbus = marxbot_isp1105_set_vbus; | |
d67d1075 | 230 | |
76eb57ec | 231 | usbh1_pdata.otg = phy; |
d67d1075 | 232 | |
2d58de28 | 233 | pdev = imx31_add_mxc_ehci_hs(1, &usbh1_pdata); |
2d58de28 | 234 | |
d3a22442 | 235 | return PTR_ERR_OR_ZERO(pdev); |
d67d1075 VL |
236 | } |
237 | ||
9e1dde33 | 238 | static const struct fsl_usb2_platform_data usb_pdata __initconst = { |
66c202ad PR |
239 | .operating_mode = FSL_USB2_DR_DEVICE, |
240 | .phy_mode = FSL_USB2_PHY_ULPI, | |
241 | }; | |
242 | ||
e00f0b4a VL |
243 | /* |
244 | * system init for baseboard usage. Will be called by mx31moboard init. | |
245 | */ | |
246 | void __init mx31moboard_marxbot_init(void) | |
247 | { | |
248 | printk(KERN_INFO "Initializing mx31marxbot peripherals\n"); | |
56c7a45b VL |
249 | |
250 | mxc_iomux_setup_multiple_pins(marxbot_pins, ARRAY_SIZE(marxbot_pins), | |
251 | "marxbot"); | |
45b131a7 | 252 | |
e335c75c VL |
253 | marxbot_init_sel_gpios(); |
254 | ||
2718c15c VL |
255 | dspics_resets_init(); |
256 | ||
6a697e3d | 257 | imx31_add_mxc_mmc(1, &sdhc2_pdata); |
10949fff | 258 | |
33c4d919 VL |
259 | spi_register_board_info(marxbot_spi_board_info, |
260 | ARRAY_SIZE(marxbot_spi_board_info)); | |
261 | ||
10949fff VL |
262 | /* battery present pin */ |
263 | gpio_request(IOMUX_TO_GPIO(MX31_PIN_LCS0), "bat-present"); | |
264 | gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_LCS0)); | |
265 | gpio_export(IOMUX_TO_GPIO(MX31_PIN_LCS0), false); | |
d67d1075 | 266 | |
9e1dde33 | 267 | imx31_add_fsl_usb2_udc(&usb_pdata); |
66c202ad | 268 | |
d67d1075 | 269 | marxbot_usbh1_init(); |
e00f0b4a | 270 | } |