Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Valentin Longchamp | e00f0b4 | 2009-02-16 12:47:51 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2009 Valentin Longchamp, EPFL Mobots group |
Valentin Longchamp | e00f0b4 | 2009-02-16 12:47:51 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
Valentin Longchamp | 04ea3c8 | 2009-11-03 18:09:51 +0100 | [diff] [blame] | 6 | #include <linux/delay.h> |
Valentin Longchamp | 45b131a | 2009-04-21 10:24:56 +0200 | [diff] [blame] | 7 | #include <linux/gpio.h> |
Valentin Longchamp | e00f0b4 | 2009-02-16 12:47:51 +0100 | [diff] [blame] | 8 | #include <linux/init.h> |
Valentin Longchamp | 45b131a | 2009-04-21 10:24:56 +0200 | [diff] [blame] | 9 | #include <linux/interrupt.h> |
Valentin Longchamp | 04ea3c8 | 2009-11-03 18:09:51 +0100 | [diff] [blame] | 10 | #include <linux/i2c.h> |
Valentin Longchamp | 33c4d91 | 2009-11-23 19:16:36 +0100 | [diff] [blame] | 11 | #include <linux/spi/spi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Valentin Longchamp | e00f0b4 | 2009-02-16 12:47:51 +0100 | [diff] [blame] | 13 | #include <linux/platform_device.h> |
Valentin Longchamp | 220bbce | 2009-04-17 15:20:25 +0200 | [diff] [blame] | 14 | #include <linux/types.h> |
Valentin Longchamp | e00f0b4 | 2009-02-16 12:47:51 +0100 | [diff] [blame] | 15 | |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 16 | #include <linux/usb/otg.h> |
| 17 | |
Marco Franchi | fa5f66c | 2017-09-25 15:55:56 -0300 | [diff] [blame] | 18 | #include "board-mx31moboard.h" |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 19 | #include "common.h" |
Uwe Kleine-König | 6a697e3 | 2010-11-12 11:10:55 +0100 | [diff] [blame] | 20 | #include "devices-imx31.h" |
Shawn Guo | 641dfe8 | 2014-05-19 20:41:52 +0800 | [diff] [blame] | 21 | #include "ehci.h" |
Shawn Guo | 50f2de6 | 2012-09-14 14:14:45 +0800 | [diff] [blame] | 22 | #include "hardware.h" |
Shawn Guo | 267dd34 | 2012-09-13 13:26:00 +0800 | [diff] [blame] | 23 | #include "iomux-mx3.h" |
Shawn Guo | 39ef634 | 2012-09-13 21:46:09 +0800 | [diff] [blame] | 24 | #include "ulpi.h" |
Valentin Longchamp | e00f0b4 | 2009-02-16 12:47:51 +0100 | [diff] [blame] | 25 | |
Valentin Longchamp | 56c7a45 | 2009-04-22 10:55:50 +0200 | [diff] [blame] | 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, |
Valentin Longchamp | 2718c15 | 2009-08-12 11:29:21 +0200 | [diff] [blame] | 32 | /* dsPIC resets */ |
| 33 | MX31_PIN_STXD5__GPIO1_21, MX31_PIN_SRXD5__GPIO1_22, |
Valentin Longchamp | 10949ff | 2009-11-03 18:09:48 +0100 | [diff] [blame] | 34 | /*battery detection */ |
| 35 | MX31_PIN_LCS0__GPIO3_23, |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 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, |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 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, |
Valentin Longchamp | 56c7a45 | 2009-04-22 10:55:50 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
Valentin Longchamp | 45b131a | 2009-04-21 10:24:56 +0200 | [diff] [blame] | 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 | { |
Valentin Longchamp | 563abb4 | 2009-08-11 17:29:21 +0200 | [diff] [blame] | 52 | return !gpio_get_value(SDHC2_WP); |
Valentin Longchamp | 45b131a | 2009-04-21 10:24:56 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static int marxbot_sdhc2_init(struct device *dev, irq_handler_t detect_irq, |
| 56 | void *data) |
| 57 | { |
Sascha Hauer | 4f163eb | 2009-05-06 12:55:50 +0200 | [diff] [blame] | 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, |
Valentin Longchamp | 45b131a | 2009-04-21 10:24:56 +0200 | [diff] [blame] | 72 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
| 73 | "sdhc2-card-detect", data); |
Sascha Hauer | 4f163eb | 2009-05-06 12:55:50 +0200 | [diff] [blame] | 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; |
Valentin Longchamp | 45b131a | 2009-04-21 10:24:56 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static void marxbot_sdhc2_exit(struct device *dev, void *data) |
| 88 | { |
| 89 | free_irq(gpio_to_irq(SDHC2_CD), data); |
Sascha Hauer | 4f163eb | 2009-05-06 12:55:50 +0200 | [diff] [blame] | 90 | gpio_free(SDHC2_WP); |
| 91 | gpio_free(SDHC2_CD); |
Valentin Longchamp | 45b131a | 2009-04-21 10:24:56 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Uwe Kleine-König | 6a697e3 | 2010-11-12 11:10:55 +0100 | [diff] [blame] | 94 | static const struct imxmmc_platform_data sdhc2_pdata __initconst = { |
Valentin Longchamp | 45b131a | 2009-04-21 10:24:56 +0200 | [diff] [blame] | 95 | .get_ro = marxbot_sdhc2_get_ro, |
| 96 | .init = marxbot_sdhc2_init, |
| 97 | .exit = marxbot_sdhc2_exit, |
| 98 | }; |
| 99 | |
Valentin Longchamp | 2718c15 | 2009-08-12 11:29:21 +0200 | [diff] [blame] | 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")) { |
Valentin Longchamp | f8594c2 | 2010-02-09 18:13:34 +0100 | [diff] [blame] | 106 | gpio_direction_output(TRSLAT_RST_B, 0); |
Valentin Longchamp | 2718c15 | 2009-08-12 11:29:21 +0200 | [diff] [blame] | 107 | gpio_export(TRSLAT_RST_B, false); |
| 108 | } |
| 109 | |
| 110 | if (!gpio_request(DSPICS_RST_B, "dspics-rst")) { |
Valentin Longchamp | f8594c2 | 2010-02-09 18:13:34 +0100 | [diff] [blame] | 111 | gpio_direction_output(DSPICS_RST_B, 0); |
Valentin Longchamp | 2718c15 | 2009-08-12 11:29:21 +0200 | [diff] [blame] | 112 | gpio_export(DSPICS_RST_B, false); |
| 113 | } |
| 114 | } |
| 115 | |
Valentin Longchamp | 33c4d91 | 2009-11-23 19:16:36 +0100 | [diff] [blame] | 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 | |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 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 | |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 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 | |
Sascha Hauer | 4bd597b | 2011-01-03 11:30:28 +0100 | [diff] [blame] | 169 | mdelay(10); |
| 170 | |
| 171 | return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED | |
| 172 | MXC_EHCI_INTERFACE_SINGLE_UNI); |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 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 | |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame] | 178 | static int marxbot_isp1105_init(struct usb_phy *otg) |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 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 | |
Heikki Krogerus | 76eb57e | 2012-02-13 13:24:14 +0200 | [diff] [blame] | 197 | static int marxbot_isp1105_set_vbus(struct usb_otg *otg, bool on) |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 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 | |
Uwe Kleine-König | 2d58de2 | 2010-11-15 11:57:49 +0100 | [diff] [blame] | 207 | static struct mxc_usbh_platform_data usbh1_pdata __initdata = { |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 208 | .init = marxbot_usbh1_hw_init, |
| 209 | .portsc = MXC_EHCI_MODE_UTMI | MXC_EHCI_SERIAL, |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | static int __init marxbot_usbh1_init(void) |
| 213 | { |
Heikki Krogerus | 76eb57e | 2012-02-13 13:24:14 +0200 | [diff] [blame] | 214 | struct usb_phy *phy; |
Uwe Kleine-König | 2d58de2 | 2010-11-15 11:57:49 +0100 | [diff] [blame] | 215 | struct platform_device *pdev; |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 216 | |
Heikki Krogerus | 76eb57e | 2012-02-13 13:24:14 +0200 | [diff] [blame] | 217 | phy = kzalloc(sizeof(*phy), GFP_KERNEL); |
| 218 | if (!phy) |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 219 | return -ENOMEM; |
| 220 | |
Heikki Krogerus | 76eb57e | 2012-02-13 13:24:14 +0200 | [diff] [blame] | 221 | phy->otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); |
| 222 | if (!phy->otg) { |
| 223 | kfree(phy); |
| 224 | return -ENOMEM; |
| 225 | } |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 226 | |
Heikki Krogerus | 76eb57e | 2012-02-13 13:24:14 +0200 | [diff] [blame] | 227 | phy->label = "ISP1105"; |
| 228 | phy->init = marxbot_isp1105_init; |
| 229 | phy->otg->set_vbus = marxbot_isp1105_set_vbus; |
| 230 | |
| 231 | usbh1_pdata.otg = phy; |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 232 | |
Uwe Kleine-König | 2d58de2 | 2010-11-15 11:57:49 +0100 | [diff] [blame] | 233 | pdev = imx31_add_mxc_ehci_hs(1, &usbh1_pdata); |
Uwe Kleine-König | 2d58de2 | 2010-11-15 11:57:49 +0100 | [diff] [blame] | 234 | |
Fabian Frederick | d3a2244 | 2014-07-04 21:03:10 +0200 | [diff] [blame] | 235 | return PTR_ERR_OR_ZERO(pdev); |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Uwe Kleine-König | 9e1dde3 | 2010-11-12 16:40:06 +0100 | [diff] [blame] | 238 | static const struct fsl_usb2_platform_data usb_pdata __initconst = { |
Philippe Rétornaz | 66c202a | 2010-05-11 16:57:50 +0200 | [diff] [blame] | 239 | .operating_mode = FSL_USB2_DR_DEVICE, |
| 240 | .phy_mode = FSL_USB2_PHY_ULPI, |
| 241 | }; |
| 242 | |
Valentin Longchamp | e00f0b4 | 2009-02-16 12:47:51 +0100 | [diff] [blame] | 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"); |
Valentin Longchamp | 56c7a45 | 2009-04-22 10:55:50 +0200 | [diff] [blame] | 249 | |
| 250 | mxc_iomux_setup_multiple_pins(marxbot_pins, ARRAY_SIZE(marxbot_pins), |
| 251 | "marxbot"); |
Valentin Longchamp | 45b131a | 2009-04-21 10:24:56 +0200 | [diff] [blame] | 252 | |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 253 | marxbot_init_sel_gpios(); |
| 254 | |
Valentin Longchamp | 2718c15 | 2009-08-12 11:29:21 +0200 | [diff] [blame] | 255 | dspics_resets_init(); |
| 256 | |
Uwe Kleine-König | 6a697e3 | 2010-11-12 11:10:55 +0100 | [diff] [blame] | 257 | imx31_add_mxc_mmc(1, &sdhc2_pdata); |
Valentin Longchamp | 10949ff | 2009-11-03 18:09:48 +0100 | [diff] [blame] | 258 | |
Valentin Longchamp | 33c4d91 | 2009-11-23 19:16:36 +0100 | [diff] [blame] | 259 | spi_register_board_info(marxbot_spi_board_info, |
| 260 | ARRAY_SIZE(marxbot_spi_board_info)); |
| 261 | |
Valentin Longchamp | 10949ff | 2009-11-03 18:09:48 +0100 | [diff] [blame] | 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); |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 266 | |
Uwe Kleine-König | 9e1dde3 | 2010-11-12 16:40:06 +0100 | [diff] [blame] | 267 | imx31_add_fsl_usb2_udc(&usb_pdata); |
Philippe Rétornaz | 66c202a | 2010-05-11 16:57:50 +0200 | [diff] [blame] | 268 | |
Valentin Longchamp | d67d107 | 2009-11-23 19:16:37 +0100 | [diff] [blame] | 269 | marxbot_usbh1_init(); |
Valentin Longchamp | e00f0b4 | 2009-02-16 12:47:51 +0100 | [diff] [blame] | 270 | } |