Sahitya Tummala | 8b4d95f | 2011-01-18 11:22:50 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 15 | * 02110-1301, USA. |
| 16 | */ |
Russell King | 2f8163b | 2011-07-26 10:53:52 +0100 | [diff] [blame] | 17 | #include <linux/gpio.h> |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/irq.h> |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 21 | #include <linux/delay.h> |
Pavankumar Kondeti | 7032d51 | 2010-12-08 13:37:07 +0530 | [diff] [blame] | 22 | #include <linux/usb/msm_hsusb.h> |
Sahitya Tummala | 8b4d95f | 2011-01-18 11:22:50 +0530 | [diff] [blame] | 23 | #include <linux/err.h> |
Stephen Boyd | bd32344 | 2011-02-23 09:37:42 -0800 | [diff] [blame] | 24 | #include <linux/clkdev.h> |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 25 | |
| 26 | #include <asm/mach-types.h> |
| 27 | #include <asm/mach/arch.h> |
| 28 | #include <asm/io.h> |
| 29 | #include <asm/setup.h> |
| 30 | |
Daniel Walker | d1c0d43 | 2010-05-05 07:17:31 -0700 | [diff] [blame] | 31 | #include <mach/irqs.h> |
| 32 | #include <mach/sirc.h> |
Sahitya Tummala | 8b4d95f | 2011-01-18 11:22:50 +0530 | [diff] [blame] | 33 | #include <mach/vreg.h> |
Ivan T. Ivanov | 5146d77 | 2013-12-30 13:15:27 -0800 | [diff] [blame] | 34 | #include <mach/clk.h> |
Arnd Bergmann | 1ef21f6 | 2012-08-24 15:14:41 +0200 | [diff] [blame] | 35 | #include <linux/platform_data/mmc-msm_sdcc.h> |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 36 | |
| 37 | #include "devices.h" |
Stephen Boyd | 4312a7e | 2012-09-05 12:28:52 -0700 | [diff] [blame] | 38 | #include "common.h" |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 39 | |
Andi Kleen | bcad6dc | 2012-10-04 17:11:28 -0700 | [diff] [blame] | 40 | static const resource_size_t qsd8x50_surf_smc91x_base __initconst = 0x70000300; |
| 41 | static const unsigned qsd8x50_surf_smc91x_gpio __initconst = 156; |
Gregory Bean | 5d73c53 | 2010-09-29 13:46:45 -0700 | [diff] [blame] | 42 | |
| 43 | /* Leave smc91x resources empty here, as we'll fill them in |
| 44 | * at run-time: they vary from board to board, and the true |
| 45 | * configuration won't be known until boot. |
| 46 | */ |
Stephen Boyd | 7c63ded | 2010-12-20 15:00:17 -0800 | [diff] [blame] | 47 | static struct resource smc91x_resources[] = { |
Gregory Bean | 5d73c53 | 2010-09-29 13:46:45 -0700 | [diff] [blame] | 48 | [0] = { |
| 49 | .flags = IORESOURCE_MEM, |
| 50 | }, |
| 51 | [1] = { |
| 52 | .flags = IORESOURCE_IRQ, |
| 53 | }, |
| 54 | }; |
| 55 | |
Stephen Boyd | 7c63ded | 2010-12-20 15:00:17 -0800 | [diff] [blame] | 56 | static struct platform_device smc91x_device = { |
Gregory Bean | 5d73c53 | 2010-09-29 13:46:45 -0700 | [diff] [blame] | 57 | .name = "smc91x", |
| 58 | .id = 0, |
| 59 | .num_resources = ARRAY_SIZE(smc91x_resources), |
| 60 | .resource = smc91x_resources, |
| 61 | }; |
| 62 | |
| 63 | static int __init msm_init_smc91x(void) |
| 64 | { |
| 65 | if (machine_is_qsd8x50_surf()) { |
| 66 | smc91x_resources[0].start = qsd8x50_surf_smc91x_base; |
| 67 | smc91x_resources[0].end = qsd8x50_surf_smc91x_base + 0xff; |
| 68 | smc91x_resources[1].start = |
| 69 | gpio_to_irq(qsd8x50_surf_smc91x_gpio); |
| 70 | smc91x_resources[1].end = |
| 71 | gpio_to_irq(qsd8x50_surf_smc91x_gpio); |
| 72 | platform_device_register(&smc91x_device); |
| 73 | } |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | module_init(msm_init_smc91x); |
| 78 | |
Pavankumar Kondeti | 7032d51 | 2010-12-08 13:37:07 +0530 | [diff] [blame] | 79 | static int hsusb_phy_init_seq[] = { |
| 80 | 0x08, 0x31, /* Increase HS Driver Amplitude */ |
| 81 | 0x20, 0x32, /* Enable and set Pre-Emphasis Depth to 10% */ |
| 82 | -1 |
| 83 | }; |
| 84 | |
Ivan T. Ivanov | 5146d77 | 2013-12-30 13:15:27 -0800 | [diff] [blame] | 85 | static int hsusb_link_clk_reset(struct clk *link_clk, bool assert) |
| 86 | { |
| 87 | int ret; |
| 88 | |
| 89 | if (assert) { |
| 90 | ret = clk_reset(link_clk, CLK_RESET_ASSERT); |
| 91 | if (ret) |
| 92 | pr_err("usb hs_clk assert failed\n"); |
| 93 | } else { |
| 94 | ret = clk_reset(link_clk, CLK_RESET_DEASSERT); |
| 95 | if (ret) |
| 96 | pr_err("usb hs_clk deassert failed\n"); |
| 97 | } |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | static int hsusb_phy_clk_reset(struct clk *phy_clk) |
| 102 | { |
| 103 | int ret; |
| 104 | |
| 105 | ret = clk_reset(phy_clk, CLK_RESET_ASSERT); |
| 106 | if (ret) { |
| 107 | pr_err("usb phy clk assert failed\n"); |
| 108 | return ret; |
| 109 | } |
| 110 | usleep_range(10000, 12000); |
| 111 | ret = clk_reset(phy_clk, CLK_RESET_DEASSERT); |
| 112 | if (ret) |
| 113 | pr_err("usb phy clk deassert failed\n"); |
| 114 | return ret; |
| 115 | } |
| 116 | |
Pavankumar Kondeti | 7032d51 | 2010-12-08 13:37:07 +0530 | [diff] [blame] | 117 | static struct msm_otg_platform_data msm_otg_pdata = { |
| 118 | .phy_init_seq = hsusb_phy_init_seq, |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 119 | .mode = USB_DR_MODE_PERIPHERAL, |
Pavankumar Kondeti | 7032d51 | 2010-12-08 13:37:07 +0530 | [diff] [blame] | 120 | .otg_control = OTG_PHY_CONTROL, |
Ivan T. Ivanov | 5146d77 | 2013-12-30 13:15:27 -0800 | [diff] [blame] | 121 | .link_clk_reset = hsusb_link_clk_reset, |
| 122 | .phy_clk_reset = hsusb_phy_clk_reset, |
Pavankumar Kondeti | 7032d51 | 2010-12-08 13:37:07 +0530 | [diff] [blame] | 123 | }; |
| 124 | |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 125 | static struct platform_device *devices[] __initdata = { |
Stephen Boyd | 421faca | 2013-06-17 10:43:18 -0700 | [diff] [blame] | 126 | &msm_clock_8x50, |
Stephen Boyd | 7bce696 | 2013-03-04 15:08:27 -0800 | [diff] [blame] | 127 | &msm_device_gpio_8x50, |
Daniel Walker | d1c0d43 | 2010-05-05 07:17:31 -0700 | [diff] [blame] | 128 | &msm_device_uart3, |
Niranjana Vishwanathapura | 88b5227 | 2010-10-06 13:52:11 -0700 | [diff] [blame] | 129 | &msm_device_smd, |
Pavankumar Kondeti | 7032d51 | 2010-12-08 13:37:07 +0530 | [diff] [blame] | 130 | &msm_device_otg, |
| 131 | &msm_device_hsusb, |
| 132 | &msm_device_hsusb_host, |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
Sahitya Tummala | 8b4d95f | 2011-01-18 11:22:50 +0530 | [diff] [blame] | 135 | static struct msm_mmc_gpio sdc1_gpio_cfg[] = { |
| 136 | {51, "sdc1_dat_3"}, |
| 137 | {52, "sdc1_dat_2"}, |
| 138 | {53, "sdc1_dat_1"}, |
| 139 | {54, "sdc1_dat_0"}, |
| 140 | {55, "sdc1_cmd"}, |
| 141 | {56, "sdc1_clk"} |
| 142 | }; |
| 143 | |
| 144 | static struct vreg *vreg_mmc; |
| 145 | static unsigned long vreg_sts; |
| 146 | |
| 147 | static uint32_t msm_sdcc_setup_power(struct device *dv, unsigned int vdd) |
| 148 | { |
| 149 | int rc = 0; |
| 150 | struct platform_device *pdev; |
| 151 | |
| 152 | pdev = container_of(dv, struct platform_device, dev); |
| 153 | |
| 154 | if (vdd == 0) { |
| 155 | if (!vreg_sts) |
| 156 | return 0; |
| 157 | |
| 158 | clear_bit(pdev->id, &vreg_sts); |
| 159 | |
| 160 | if (!vreg_sts) { |
| 161 | rc = vreg_disable(vreg_mmc); |
| 162 | if (rc) |
| 163 | pr_err("vreg_mmc disable failed for slot " |
| 164 | "%d: %d\n", pdev->id, rc); |
| 165 | } |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | if (!vreg_sts) { |
| 170 | rc = vreg_set_level(vreg_mmc, 2900); |
| 171 | if (rc) |
| 172 | pr_err("vreg_mmc set level failed for slot %d: %d\n", |
| 173 | pdev->id, rc); |
| 174 | rc = vreg_enable(vreg_mmc); |
| 175 | if (rc) |
| 176 | pr_err("vreg_mmc enable failed for slot %d: %d\n", |
| 177 | pdev->id, rc); |
| 178 | } |
| 179 | set_bit(pdev->id, &vreg_sts); |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | static struct msm_mmc_gpio_data sdc1_gpio = { |
| 184 | .gpio = sdc1_gpio_cfg, |
| 185 | .size = ARRAY_SIZE(sdc1_gpio_cfg), |
| 186 | }; |
| 187 | |
| 188 | static struct msm_mmc_platform_data qsd8x50_sdc1_data = { |
| 189 | .ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29, |
| 190 | .translate_vdd = msm_sdcc_setup_power, |
| 191 | .gpio_data = &sdc1_gpio, |
| 192 | }; |
| 193 | |
| 194 | static void __init qsd8x50_init_mmc(void) |
| 195 | { |
David Brown | 62f0988 | 2011-03-29 11:48:45 -0700 | [diff] [blame] | 196 | vreg_mmc = vreg_get(NULL, "gp5"); |
Sahitya Tummala | 8b4d95f | 2011-01-18 11:22:50 +0530 | [diff] [blame] | 197 | |
| 198 | if (IS_ERR(vreg_mmc)) { |
| 199 | pr_err("vreg get for vreg_mmc failed (%ld)\n", |
| 200 | PTR_ERR(vreg_mmc)); |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | msm_add_sdcc(1, &qsd8x50_sdc1_data, 0, 0); |
| 205 | } |
| 206 | |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 207 | static void __init qsd8x50_map_io(void) |
| 208 | { |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 209 | msm_map_qsd8x50_io(); |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Daniel Walker | d1c0d43 | 2010-05-05 07:17:31 -0700 | [diff] [blame] | 212 | static void __init qsd8x50_init_irq(void) |
| 213 | { |
| 214 | msm_init_irq(); |
| 215 | msm_init_sirc(); |
| 216 | } |
| 217 | |
| 218 | static void __init qsd8x50_init(void) |
| 219 | { |
Pavankumar Kondeti | 7032d51 | 2010-12-08 13:37:07 +0530 | [diff] [blame] | 220 | msm_device_otg.dev.platform_data = &msm_otg_pdata; |
| 221 | msm_device_hsusb.dev.parent = &msm_device_otg.dev; |
| 222 | msm_device_hsusb_host.dev.parent = &msm_device_otg.dev; |
Daniel Walker | d1c0d43 | 2010-05-05 07:17:31 -0700 | [diff] [blame] | 223 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
Sahitya Tummala | 8b4d95f | 2011-01-18 11:22:50 +0530 | [diff] [blame] | 224 | qsd8x50_init_mmc(); |
Daniel Walker | d1c0d43 | 2010-05-05 07:17:31 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Shawn Guo | c633c53 | 2012-05-02 15:53:20 +0800 | [diff] [blame] | 227 | static void __init qsd8x50_init_late(void) |
| 228 | { |
| 229 | smd_debugfs_init(); |
| 230 | } |
| 231 | |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 232 | MACHINE_START(QSD8X50_SURF, "QCT QSD8X50 SURF") |
Nicolas Pitre | f631dd4 | 2011-07-05 22:38:14 -0400 | [diff] [blame] | 233 | .atag_offset = 0x100, |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 234 | .map_io = qsd8x50_map_io, |
| 235 | .init_irq = qsd8x50_init_irq, |
| 236 | .init_machine = qsd8x50_init, |
Shawn Guo | c633c53 | 2012-05-02 15:53:20 +0800 | [diff] [blame] | 237 | .init_late = qsd8x50_init_late, |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 238 | .init_time = qsd8x50_timer_init, |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 239 | MACHINE_END |
| 240 | |
Daniel Walker | d1c0d43 | 2010-05-05 07:17:31 -0700 | [diff] [blame] | 241 | MACHINE_START(QSD8X50A_ST1_5, "QCT QSD8X50A ST1.5") |
Nicolas Pitre | f631dd4 | 2011-07-05 22:38:14 -0400 | [diff] [blame] | 242 | .atag_offset = 0x100, |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 243 | .map_io = qsd8x50_map_io, |
| 244 | .init_irq = qsd8x50_init_irq, |
| 245 | .init_machine = qsd8x50_init, |
Shawn Guo | c633c53 | 2012-05-02 15:53:20 +0800 | [diff] [blame] | 246 | .init_late = qsd8x50_init_late, |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 247 | .init_time = qsd8x50_timer_init, |
Daniel Walker | a32d2fe | 2010-02-25 11:38:39 -0800 | [diff] [blame] | 248 | MACHINE_END |