Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1 | /* ehci-msm-hsic.c - HSUSB Host Controller Driver Implementation |
| 2 | * |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 4 | * |
| 5 | * Partly derived from ehci-fsl.c and ehci-hcd.c |
| 6 | * Copyright (c) 2000-2004 by David Brownell |
| 7 | * Copyright (c) 2005 MontaVista Software |
| 8 | * |
| 9 | * All source code in this file is licensed under the following license except |
| 10 | * where indicated. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License version 2 as published |
| 14 | * by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 19 | * |
| 20 | * See the GNU General Public License for more details. |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, you can find it at http://www.fsf.org |
| 23 | */ |
| 24 | |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/clk.h> |
| 27 | #include <linux/err.h> |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 28 | #include <linux/debugfs.h> |
| 29 | #include <linux/seq_file.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 30 | #include <linux/pm_runtime.h> |
| 31 | #include <linux/regulator/consumer.h> |
| 32 | |
| 33 | #include <linux/usb/msm_hsusb_hw.h> |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 34 | #include <linux/usb/msm_hsusb.h> |
| 35 | #include <linux/gpio.h> |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 36 | #include <linux/spinlock.h> |
| 37 | |
| 38 | #include <mach/msm_bus.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 39 | #include <mach/clk.h> |
| 40 | #include <mach/msm_iomap.h> |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 41 | #include <mach/msm_xo.h> |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 42 | #include <linux/spinlock.h> |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 43 | #include <linux/cpu.h> |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 44 | #include <mach/rpm-regulator.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 45 | |
| 46 | #define MSM_USB_BASE (hcd->regs) |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 47 | #define USB_REG_START_OFFSET 0x90 |
| 48 | #define USB_REG_END_OFFSET 0x250 |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 49 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 50 | static struct workqueue_struct *ehci_wq; |
| 51 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 52 | struct msm_hsic_hcd { |
| 53 | struct ehci_hcd ehci; |
| 54 | struct device *dev; |
| 55 | struct clk *ahb_clk; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 56 | struct clk *core_clk; |
| 57 | struct clk *alt_core_clk; |
| 58 | struct clk *phy_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 59 | struct clk *cal_clk; |
| 60 | struct regulator *hsic_vddcx; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 61 | atomic_t in_lpm; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 62 | int peripheral_status_irq; |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 63 | int wakeup_irq; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 64 | int wakeup_gpio; |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 65 | bool wakeup_irq_enabled; |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 66 | bool irq_enabled; |
| 67 | bool async_int; |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 68 | uint32_t bus_perf_client; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 69 | uint32_t wakeup_int_cnt; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 70 | enum usb_vdd_type vdd_type; |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 71 | |
| 72 | struct work_struct bus_vote_w; |
| 73 | bool bus_vote; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 74 | }; |
| 75 | |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 76 | struct msm_hsic_hcd *__mehci; |
| 77 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 78 | static bool debug_bus_voting_enabled = true; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 79 | |
| 80 | static unsigned int enable_dbg_log = 1; |
| 81 | module_param(enable_dbg_log, uint, S_IRUGO | S_IWUSR); |
| 82 | /*by default log ep0 and efs sync ep*/ |
| 83 | static unsigned int ep_addr_rxdbg_mask = 9; |
| 84 | module_param(ep_addr_rxdbg_mask, uint, S_IRUGO | S_IWUSR); |
| 85 | static unsigned int ep_addr_txdbg_mask = 9; |
| 86 | module_param(ep_addr_txdbg_mask, uint, S_IRUGO | S_IWUSR); |
| 87 | |
| 88 | /* Maximum debug message length */ |
| 89 | #define DBG_MSG_LEN 100UL |
| 90 | |
| 91 | /* Maximum number of messages */ |
| 92 | #define DBG_MAX_MSG 256UL |
| 93 | |
| 94 | #define TIME_BUF_LEN 20 |
| 95 | |
| 96 | enum event_type { |
| 97 | EVENT_UNDEF = -1, |
| 98 | URB_SUBMIT, |
| 99 | URB_COMPLETE, |
| 100 | EVENT_NONE, |
| 101 | }; |
| 102 | |
| 103 | #define EVENT_STR_LEN 5 |
| 104 | |
| 105 | static char *event_to_str(enum event_type e) |
| 106 | { |
| 107 | switch (e) { |
| 108 | case URB_SUBMIT: |
| 109 | return "S"; |
| 110 | case URB_COMPLETE: |
| 111 | return "C"; |
| 112 | case EVENT_NONE: |
| 113 | return "NONE"; |
| 114 | default: |
| 115 | return "UNDEF"; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | static enum event_type str_to_event(const char *name) |
| 120 | { |
| 121 | if (!strncasecmp("S", name, EVENT_STR_LEN)) |
| 122 | return URB_SUBMIT; |
| 123 | if (!strncasecmp("C", name, EVENT_STR_LEN)) |
| 124 | return URB_COMPLETE; |
| 125 | if (!strncasecmp("", name, EVENT_STR_LEN)) |
| 126 | return EVENT_NONE; |
| 127 | |
| 128 | return EVENT_UNDEF; |
| 129 | } |
| 130 | |
| 131 | /*log ep0 activity*/ |
| 132 | static struct { |
| 133 | char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */ |
| 134 | unsigned idx; /* index */ |
| 135 | rwlock_t lck; /* lock */ |
| 136 | } dbg_hsic_ctrl = { |
| 137 | .idx = 0, |
| 138 | .lck = __RW_LOCK_UNLOCKED(lck) |
| 139 | }; |
| 140 | |
| 141 | static struct { |
| 142 | char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */ |
| 143 | unsigned idx; /* index */ |
| 144 | rwlock_t lck; /* lock */ |
| 145 | } dbg_hsic_data = { |
| 146 | .idx = 0, |
| 147 | .lck = __RW_LOCK_UNLOCKED(lck) |
| 148 | }; |
| 149 | |
| 150 | /** |
| 151 | * dbg_inc: increments debug event index |
| 152 | * @idx: buffer index |
| 153 | */ |
| 154 | static void dbg_inc(unsigned *idx) |
| 155 | { |
| 156 | *idx = (*idx + 1) & (DBG_MAX_MSG-1); |
| 157 | } |
| 158 | |
| 159 | /*get_timestamp - returns time of day in us */ |
| 160 | static char *get_timestamp(char *tbuf) |
| 161 | { |
| 162 | unsigned long long t; |
| 163 | unsigned long nanosec_rem; |
| 164 | |
| 165 | t = cpu_clock(smp_processor_id()); |
| 166 | nanosec_rem = do_div(t, 1000000000)/1000; |
| 167 | scnprintf(tbuf, TIME_BUF_LEN, "[%5lu.%06lu] ", (unsigned long)t, |
| 168 | nanosec_rem); |
| 169 | return tbuf; |
| 170 | } |
| 171 | |
| 172 | static int allow_dbg_log(int ep_addr) |
| 173 | { |
| 174 | int dir, num; |
| 175 | |
| 176 | dir = ep_addr & USB_DIR_IN ? USB_DIR_IN : USB_DIR_OUT; |
| 177 | num = ep_addr & ~USB_DIR_IN; |
| 178 | num = 1 << num; |
| 179 | |
| 180 | if ((dir == USB_DIR_IN) && (num & ep_addr_rxdbg_mask)) |
| 181 | return 1; |
| 182 | if ((dir == USB_DIR_OUT) && (num & ep_addr_txdbg_mask)) |
| 183 | return 1; |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | static void dbg_log_event(struct urb *urb, char * event, unsigned extra) |
| 189 | { |
| 190 | unsigned long flags; |
| 191 | int ep_addr; |
| 192 | char tbuf[TIME_BUF_LEN]; |
| 193 | |
| 194 | if (!enable_dbg_log) |
| 195 | return; |
| 196 | |
| 197 | if (!urb) { |
| 198 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 199 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], DBG_MSG_LEN, |
| 200 | "%s: %s : %u\n", get_timestamp(tbuf), event, extra); |
| 201 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 202 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | ep_addr = urb->ep->desc.bEndpointAddress; |
| 207 | if (!allow_dbg_log(ep_addr)) |
| 208 | return; |
| 209 | |
| 210 | if ((ep_addr & 0x0f) == 0x0) { |
| 211 | /*submit event*/ |
| 212 | if (!str_to_event(event)) { |
| 213 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 214 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], |
| 215 | DBG_MSG_LEN, "%s: [%s : %p]:[%s] " |
| 216 | "%02x %02x %04x %04x %04x %u %d\n", |
| 217 | get_timestamp(tbuf), event, urb, |
| 218 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 219 | urb->setup_packet[0], urb->setup_packet[1], |
| 220 | (urb->setup_packet[3] << 8) | |
| 221 | urb->setup_packet[2], |
| 222 | (urb->setup_packet[5] << 8) | |
| 223 | urb->setup_packet[4], |
| 224 | (urb->setup_packet[7] << 8) | |
| 225 | urb->setup_packet[6], |
| 226 | urb->transfer_buffer_length, urb->status); |
| 227 | |
| 228 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 229 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 230 | } else { |
| 231 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 232 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], |
| 233 | DBG_MSG_LEN, "%s: [%s : %p]:[%s] %u %d\n", |
| 234 | get_timestamp(tbuf), event, urb, |
| 235 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 236 | urb->actual_length, extra); |
| 237 | |
| 238 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 239 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 240 | } |
| 241 | } else { |
| 242 | write_lock_irqsave(&dbg_hsic_data.lck, flags); |
| 243 | scnprintf(dbg_hsic_data.buf[dbg_hsic_data.idx], DBG_MSG_LEN, |
| 244 | "%s: [%s : %p]:ep%d[%s] %u %d\n", |
| 245 | get_timestamp(tbuf), event, urb, ep_addr & 0x0f, |
| 246 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 247 | str_to_event(event) ? urb->actual_length : |
| 248 | urb->transfer_buffer_length, |
| 249 | str_to_event(event) ? extra : urb->status); |
| 250 | |
| 251 | dbg_inc(&dbg_hsic_data.idx); |
| 252 | write_unlock_irqrestore(&dbg_hsic_data.lck, flags); |
| 253 | } |
| 254 | } |
| 255 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 256 | static inline struct msm_hsic_hcd *hcd_to_hsic(struct usb_hcd *hcd) |
| 257 | { |
| 258 | return (struct msm_hsic_hcd *) (hcd->hcd_priv); |
| 259 | } |
| 260 | |
| 261 | static inline struct usb_hcd *hsic_to_hcd(struct msm_hsic_hcd *mehci) |
| 262 | { |
| 263 | return container_of((void *) mehci, struct usb_hcd, hcd_priv); |
| 264 | } |
| 265 | |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 266 | static void dump_hsic_regs(struct usb_hcd *hcd) |
| 267 | { |
| 268 | int i; |
| 269 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 270 | |
| 271 | if (atomic_read(&mehci->in_lpm)) |
| 272 | return; |
| 273 | |
| 274 | for (i = USB_REG_START_OFFSET; i <= USB_REG_END_OFFSET; i += 0x10) |
| 275 | pr_info("%p: %08x\t%08x\t%08x\t%08x\n", hcd->regs + i, |
| 276 | readl_relaxed(hcd->regs + i), |
| 277 | readl_relaxed(hcd->regs + i + 4), |
| 278 | readl_relaxed(hcd->regs + i + 8), |
| 279 | readl_relaxed(hcd->regs + i + 0xc)); |
| 280 | } |
| 281 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 282 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) |
| 283 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 284 | #define USB_PHY_VDD_DIG_VOL_NONE 0 /*uV */ |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 285 | #define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */ |
| 286 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 287 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 288 | #define HSIC_DBG1_REG 0x38 |
| 289 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 290 | static const int vdd_val[VDD_TYPE_MAX][VDD_VAL_MAX] = { |
| 291 | { /* VDD_CX CORNER Voting */ |
| 292 | [VDD_NONE] = RPM_VREG_CORNER_NONE, |
| 293 | [VDD_MIN] = RPM_VREG_CORNER_NOMINAL, |
| 294 | [VDD_MAX] = RPM_VREG_CORNER_HIGH, |
| 295 | }, |
| 296 | { /* VDD_CX Voltage Voting */ |
| 297 | [VDD_NONE] = USB_PHY_VDD_DIG_VOL_NONE, |
| 298 | [VDD_MIN] = USB_PHY_VDD_DIG_VOL_MIN, |
| 299 | [VDD_MAX] = USB_PHY_VDD_DIG_VOL_MAX, |
| 300 | }, |
| 301 | }; |
| 302 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 303 | static int msm_hsic_init_vddcx(struct msm_hsic_hcd *mehci, int init) |
| 304 | { |
| 305 | int ret = 0; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 306 | int none_vol, min_vol, max_vol; |
| 307 | |
| 308 | if (!mehci->hsic_vddcx) { |
| 309 | mehci->vdd_type = VDDCX_CORNER; |
| 310 | mehci->hsic_vddcx = devm_regulator_get(mehci->dev, |
| 311 | "hsic_vdd_dig"); |
| 312 | if (IS_ERR(mehci->hsic_vddcx)) { |
| 313 | mehci->hsic_vddcx = devm_regulator_get(mehci->dev, |
| 314 | "HSIC_VDDCX"); |
| 315 | if (IS_ERR(mehci->hsic_vddcx)) { |
| 316 | dev_err(mehci->dev, "unable to get hsic vddcx\n"); |
| 317 | return PTR_ERR(mehci->hsic_vddcx); |
| 318 | } |
| 319 | mehci->vdd_type = VDDCX; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | none_vol = vdd_val[mehci->vdd_type][VDD_NONE]; |
| 324 | min_vol = vdd_val[mehci->vdd_type][VDD_MIN]; |
| 325 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 326 | |
| 327 | if (!init) |
| 328 | goto disable_reg; |
| 329 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 330 | ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 331 | if (ret) { |
| 332 | dev_err(mehci->dev, "unable to set the voltage" |
| 333 | "for hsic vddcx\n"); |
Mayank Rana | 189ac05 | 2012-03-24 04:35:02 +0530 | [diff] [blame] | 334 | return ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 335 | } |
| 336 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 337 | ret = regulator_enable(mehci->hsic_vddcx); |
| 338 | if (ret) { |
| 339 | dev_err(mehci->dev, "unable to enable hsic vddcx\n"); |
| 340 | goto reg_enable_err; |
| 341 | } |
| 342 | |
| 343 | return 0; |
| 344 | |
| 345 | disable_reg: |
| 346 | regulator_disable(mehci->hsic_vddcx); |
| 347 | reg_enable_err: |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 348 | regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol); |
| 349 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 350 | return ret; |
| 351 | |
| 352 | } |
| 353 | |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 354 | static int ulpi_read(struct msm_hsic_hcd *mehci, u32 reg) |
| 355 | { |
| 356 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
| 357 | unsigned long timeout; |
| 358 | |
| 359 | /* initiate read operation */ |
| 360 | writel_relaxed(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg), |
| 361 | USB_ULPI_VIEWPORT); |
| 362 | |
| 363 | /* wait for completion */ |
| 364 | timeout = jiffies + usecs_to_jiffies(ULPI_IO_TIMEOUT_USEC); |
| 365 | while (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN) { |
| 366 | if (time_after(jiffies, timeout)) { |
| 367 | dev_err(mehci->dev, "ulpi_read: timeout %08x\n", |
| 368 | readl_relaxed(USB_ULPI_VIEWPORT)); |
| 369 | return -ETIMEDOUT; |
| 370 | } |
| 371 | udelay(1); |
| 372 | } |
| 373 | |
| 374 | return ULPI_DATA_READ(readl_relaxed(USB_ULPI_VIEWPORT)); |
| 375 | } |
| 376 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 377 | static int ulpi_write(struct msm_hsic_hcd *mehci, u32 val, u32 reg) |
| 378 | { |
| 379 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
| 380 | int cnt = 0; |
| 381 | |
| 382 | /* initiate write operation */ |
| 383 | writel_relaxed(ULPI_RUN | ULPI_WRITE | |
| 384 | ULPI_ADDR(reg) | ULPI_DATA(val), |
| 385 | USB_ULPI_VIEWPORT); |
| 386 | |
| 387 | /* wait for completion */ |
| 388 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 389 | if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 390 | break; |
| 391 | udelay(1); |
| 392 | cnt++; |
| 393 | } |
| 394 | |
| 395 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
| 396 | dev_err(mehci->dev, "ulpi_write: timeout\n"); |
| 397 | return -ETIMEDOUT; |
| 398 | } |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 403 | #define HSIC_DBG1 0X38 |
| 404 | #define ULPI_MANUAL_ENABLE BIT(4) |
| 405 | #define ULPI_LINESTATE_DATA BIT(5) |
| 406 | #define ULPI_LINESTATE_STROBE BIT(6) |
| 407 | static void ehci_msm_enable_ulpi_control(struct usb_hcd *hcd, u32 linestate) |
| 408 | { |
| 409 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 410 | int val; |
| 411 | |
| 412 | switch (linestate) { |
| 413 | case PORT_RESET: |
| 414 | val = ulpi_read(mehci, HSIC_DBG1); |
| 415 | val |= ULPI_MANUAL_ENABLE; |
| 416 | val &= ~(ULPI_LINESTATE_DATA | ULPI_LINESTATE_STROBE); |
| 417 | ulpi_write(mehci, val, HSIC_DBG1); |
| 418 | break; |
| 419 | default: |
| 420 | pr_info("%s: Unknown linestate:%0x\n", __func__, linestate); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | static void ehci_msm_disable_ulpi_control(struct usb_hcd *hcd) |
| 425 | { |
| 426 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 427 | int val; |
| 428 | |
| 429 | val = ulpi_read(mehci, HSIC_DBG1); |
| 430 | val &= ~ULPI_MANUAL_ENABLE; |
| 431 | ulpi_write(mehci, val, HSIC_DBG1); |
| 432 | } |
| 433 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 434 | static int msm_hsic_config_gpios(struct msm_hsic_hcd *mehci, int gpio_en) |
| 435 | { |
| 436 | int rc = 0; |
| 437 | struct msm_hsic_host_platform_data *pdata; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 438 | static int gpio_status; |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 439 | |
| 440 | pdata = mehci->dev->platform_data; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 441 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 442 | if (!pdata || !pdata->strobe || !pdata->data) |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 443 | return rc; |
| 444 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 445 | if (gpio_status == gpio_en) |
| 446 | return 0; |
| 447 | |
| 448 | gpio_status = gpio_en; |
| 449 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 450 | if (!gpio_en) |
| 451 | goto free_gpio; |
| 452 | |
| 453 | rc = gpio_request(pdata->strobe, "HSIC_STROBE_GPIO"); |
| 454 | if (rc < 0) { |
| 455 | dev_err(mehci->dev, "gpio request failed for HSIC STROBE\n"); |
| 456 | return rc; |
| 457 | } |
| 458 | |
| 459 | rc = gpio_request(pdata->data, "HSIC_DATA_GPIO"); |
| 460 | if (rc < 0) { |
| 461 | dev_err(mehci->dev, "gpio request failed for HSIC DATA\n"); |
| 462 | goto free_strobe; |
| 463 | } |
| 464 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 465 | if (mehci->wakeup_gpio) { |
| 466 | rc = gpio_request(mehci->wakeup_gpio, "HSIC_WAKEUP_GPIO"); |
| 467 | if (rc < 0) { |
| 468 | dev_err(mehci->dev, "gpio request failed for HSIC WAKEUP\n"); |
| 469 | goto free_data; |
| 470 | } |
| 471 | } |
| 472 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 473 | return 0; |
| 474 | |
| 475 | free_gpio: |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 476 | if (mehci->wakeup_gpio) |
| 477 | gpio_free(mehci->wakeup_gpio); |
| 478 | free_data: |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 479 | gpio_free(pdata->data); |
| 480 | free_strobe: |
| 481 | gpio_free(pdata->strobe); |
| 482 | |
| 483 | return rc; |
| 484 | } |
| 485 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 486 | static void msm_hsic_clk_reset(struct msm_hsic_hcd *mehci) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 487 | { |
| 488 | int ret; |
| 489 | |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 490 | ret = clk_reset(mehci->core_clk, CLK_RESET_ASSERT); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 491 | if (ret) { |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 492 | dev_err(mehci->dev, "hsic clk assert failed:%d\n", ret); |
| 493 | return; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 494 | } |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 495 | clk_disable(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 496 | |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 497 | ret = clk_reset(mehci->core_clk, CLK_RESET_DEASSERT); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 498 | if (ret) |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 499 | dev_err(mehci->dev, "hsic clk deassert failed:%d\n", ret); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 500 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 501 | usleep_range(10000, 12000); |
| 502 | |
| 503 | clk_enable(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 504 | } |
| 505 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 506 | #define HSIC_STROBE_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C0) |
| 507 | #define HSIC_DATA_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C4) |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 508 | #define HSIC_CAL_PAD_CTL (MSM_TLMM_BASE+0x20C8) |
| 509 | #define HSIC_LV_MODE 0x04 |
| 510 | #define HSIC_PAD_CALIBRATION 0xA8 |
| 511 | #define HSIC_GPIO_PAD_VAL 0x0A0AAA10 |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 512 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) |
| 513 | static int msm_hsic_reset(struct msm_hsic_hcd *mehci) |
| 514 | { |
| 515 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 516 | int ret; |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 517 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 518 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 519 | msm_hsic_clk_reset(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 520 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 521 | /* select ulpi phy */ |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 522 | writel_relaxed(0x80000000, USB_PORTSC); |
| 523 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 524 | mb(); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 525 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 526 | /* HSIC init sequence when HSIC signals (Strobe/Data) are |
| 527 | routed via GPIOs */ |
| 528 | if (pdata && pdata->strobe && pdata->data) { |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 529 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 530 | /* Enable LV_MODE in HSIC_CAL_PAD_CTL register */ |
| 531 | writel_relaxed(HSIC_LV_MODE, HSIC_CAL_PAD_CTL); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 532 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 533 | mb(); |
| 534 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 535 | /*set periodic calibration interval to ~2.048sec in |
| 536 | HSIC_IO_CAL_REG */ |
| 537 | ulpi_write(mehci, 0xFF, 0x33); |
| 538 | |
| 539 | /* Enable periodic IO calibration in HSIC_CFG register */ |
| 540 | ulpi_write(mehci, HSIC_PAD_CALIBRATION, 0x30); |
| 541 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 542 | /* Configure GPIO pins for HSIC functionality mode */ |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 543 | ret = msm_hsic_config_gpios(mehci, 1); |
| 544 | if (ret) { |
| 545 | dev_err(mehci->dev, " gpio configuarion failed\n"); |
| 546 | return ret; |
| 547 | } |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 548 | /* Set LV_MODE=0x1 and DCC=0x2 in HSIC_GPIO PAD_CTL register */ |
| 549 | writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_STROBE_GPIO_PAD_CTL); |
| 550 | writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_DATA_GPIO_PAD_CTL); |
| 551 | |
| 552 | mb(); |
| 553 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 554 | /* Enable HSIC mode in HSIC_CFG register */ |
| 555 | ulpi_write(mehci, 0x01, 0x31); |
| 556 | } else { |
| 557 | /* HSIC init sequence when HSIC signals (Strobe/Data) are routed |
| 558 | via dedicated I/O */ |
| 559 | |
| 560 | /* programmable length of connect signaling (33.2ns) */ |
| 561 | ret = ulpi_write(mehci, 3, HSIC_DBG1_REG); |
| 562 | if (ret) { |
| 563 | pr_err("%s: Unable to program length of connect " |
| 564 | "signaling\n", __func__); |
| 565 | } |
| 566 | |
| 567 | /*set periodic calibration interval to ~2.048sec in |
| 568 | HSIC_IO_CAL_REG */ |
| 569 | ulpi_write(mehci, 0xFF, 0x33); |
| 570 | |
| 571 | /* Enable HSIC mode in HSIC_CFG register */ |
| 572 | ulpi_write(mehci, 0xA9, 0x30); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 573 | } |
| 574 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 575 | /*disable auto resume*/ |
| 576 | ulpi_write(mehci, ULPI_IFC_CTRL_AUTORESUME, ULPI_CLR(ULPI_IFC_CTRL)); |
| 577 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
| 582 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) |
| 583 | |
| 584 | #ifdef CONFIG_PM_SLEEP |
| 585 | static int msm_hsic_suspend(struct msm_hsic_hcd *mehci) |
| 586 | { |
| 587 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 588 | int cnt = 0, ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 589 | u32 val; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 590 | int none_vol, max_vol; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 591 | |
| 592 | if (atomic_read(&mehci->in_lpm)) { |
| 593 | dev_dbg(mehci->dev, "%s called in lpm\n", __func__); |
| 594 | return 0; |
| 595 | } |
| 596 | |
Hemant Kumar | 7f37463 | 2012-05-31 20:10:32 -0700 | [diff] [blame] | 597 | if (!(readl_relaxed(USB_PORTSC) & PORT_PE)) { |
| 598 | dev_dbg(mehci->dev, "%s:port is not enabled skip suspend\n", |
| 599 | __func__); |
| 600 | return -EAGAIN; |
| 601 | } |
| 602 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 603 | disable_irq(hcd->irq); |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 604 | |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 605 | /* make sure we don't race against the root hub being resumed */ |
| 606 | if (HCD_RH_RUNNING(hcd) || HCD_WAKEUP_PENDING(hcd) || |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 607 | readl_relaxed(USB_PORTSC) & PORT_RESUME) { |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 608 | dev_warn(mehci->dev, "%s: Root hub is not suspended\n", |
| 609 | __func__); |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 610 | enable_irq(hcd->irq); |
| 611 | return -EBUSY; |
| 612 | } |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 613 | mehci->irq_enabled = false; |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 614 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 615 | /* |
| 616 | * PHY may take some time or even fail to enter into low power |
| 617 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link |
| 618 | * in failure case. |
| 619 | */ |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 620 | val = readl_relaxed(USB_PORTSC); |
| 621 | val &= ~PORT_RWC_BITS; |
| 622 | val |= PORTSC_PHCD; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 623 | writel_relaxed(val, USB_PORTSC); |
| 624 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 625 | if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD) |
| 626 | break; |
| 627 | udelay(1); |
| 628 | cnt++; |
| 629 | } |
| 630 | |
| 631 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) { |
| 632 | dev_err(mehci->dev, "Unable to suspend PHY\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 633 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 634 | msm_hsic_reset(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | /* |
| 638 | * PHY has capability to generate interrupt asynchronously in low |
| 639 | * power mode (LPM). This interrupt is level triggered. So USB IRQ |
| 640 | * line must be disabled till async interrupt enable bit is cleared |
| 641 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to |
| 642 | * block data communication from PHY. |
| 643 | */ |
| 644 | writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL | |
| 645 | ULPI_STP_CTRL, USB_USBCMD); |
| 646 | |
| 647 | /* |
| 648 | * Ensure that hardware is put in low power mode before |
| 649 | * clocks are turned OFF and VDD is allowed to minimize. |
| 650 | */ |
| 651 | mb(); |
| 652 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 653 | clk_disable_unprepare(mehci->core_clk); |
| 654 | clk_disable_unprepare(mehci->phy_clk); |
| 655 | clk_disable_unprepare(mehci->cal_clk); |
| 656 | clk_disable_unprepare(mehci->ahb_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 657 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 658 | none_vol = vdd_val[mehci->vdd_type][VDD_NONE]; |
| 659 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
| 660 | |
| 661 | ret = regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 662 | if (ret < 0) |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 663 | dev_err(mehci->dev, "unable to set vddcx voltage for VDD MIN\n"); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 664 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 665 | if (mehci->bus_perf_client && debug_bus_voting_enabled) { |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 666 | mehci->bus_vote = false; |
| 667 | queue_work(ehci_wq, &mehci->bus_vote_w); |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 668 | } |
| 669 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 670 | atomic_set(&mehci->in_lpm, 1); |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 671 | mehci->irq_enabled = true; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 672 | enable_irq(hcd->irq); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 673 | |
| 674 | mehci->wakeup_irq_enabled = 1; |
| 675 | enable_irq_wake(mehci->wakeup_irq); |
| 676 | enable_irq(mehci->wakeup_irq); |
| 677 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 678 | dev_info(mehci->dev, "HSIC-USB in low power mode\n"); |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | static int msm_hsic_resume(struct msm_hsic_hcd *mehci) |
| 684 | { |
| 685 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 686 | int cnt = 0, ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 687 | unsigned temp; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 688 | int min_vol, max_vol; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 689 | |
| 690 | if (!atomic_read(&mehci->in_lpm)) { |
| 691 | dev_dbg(mehci->dev, "%s called in !in_lpm\n", __func__); |
| 692 | return 0; |
| 693 | } |
| 694 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 695 | if (mehci->wakeup_irq_enabled) { |
| 696 | disable_irq_wake(mehci->wakeup_irq); |
| 697 | disable_irq_nosync(mehci->wakeup_irq); |
| 698 | mehci->wakeup_irq_enabled = 0; |
| 699 | } |
| 700 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 701 | if (mehci->bus_perf_client && debug_bus_voting_enabled) { |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 702 | mehci->bus_vote = true; |
| 703 | queue_work(ehci_wq, &mehci->bus_vote_w); |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 704 | } |
| 705 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 706 | min_vol = vdd_val[mehci->vdd_type][VDD_MIN]; |
| 707 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
| 708 | |
| 709 | ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 710 | if (ret < 0) |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 711 | dev_err(mehci->dev, "unable to set nominal vddcx voltage (no VDD MIN)\n"); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 712 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 713 | clk_prepare_enable(mehci->core_clk); |
| 714 | clk_prepare_enable(mehci->phy_clk); |
| 715 | clk_prepare_enable(mehci->cal_clk); |
| 716 | clk_prepare_enable(mehci->ahb_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 717 | |
| 718 | temp = readl_relaxed(USB_USBCMD); |
| 719 | temp &= ~ASYNC_INTR_CTRL; |
| 720 | temp &= ~ULPI_STP_CTRL; |
| 721 | writel_relaxed(temp, USB_USBCMD); |
| 722 | |
| 723 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) |
| 724 | goto skip_phy_resume; |
| 725 | |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 726 | temp = readl_relaxed(USB_PORTSC); |
| 727 | temp &= ~(PORT_RWC_BITS | PORTSC_PHCD); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 728 | writel_relaxed(temp, USB_PORTSC); |
| 729 | while (cnt < PHY_RESUME_TIMEOUT_USEC) { |
| 730 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD) && |
| 731 | (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE)) |
| 732 | break; |
| 733 | udelay(1); |
| 734 | cnt++; |
| 735 | } |
| 736 | |
| 737 | if (cnt >= PHY_RESUME_TIMEOUT_USEC) { |
| 738 | /* |
| 739 | * This is a fatal error. Reset the link and |
| 740 | * PHY to make hsic working. |
| 741 | */ |
| 742 | dev_err(mehci->dev, "Unable to resume USB. Reset the hsic\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 743 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 744 | msm_hsic_reset(mehci); |
| 745 | } |
| 746 | |
| 747 | skip_phy_resume: |
| 748 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 749 | usb_hcd_resume_root_hub(hcd); |
| 750 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 751 | atomic_set(&mehci->in_lpm, 0); |
| 752 | |
| 753 | if (mehci->async_int) { |
| 754 | mehci->async_int = false; |
| 755 | pm_runtime_put_noidle(mehci->dev); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 756 | } |
| 757 | |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 758 | if (!mehci->irq_enabled) { |
| 759 | enable_irq(hcd->irq); |
| 760 | mehci->irq_enabled = true; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 763 | pm_relax(mehci->dev); |
| 764 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 765 | dev_info(mehci->dev, "HSIC-USB exited from low power mode\n"); |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | #endif |
| 770 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 771 | static void ehci_hsic_bus_vote_w(struct work_struct *w) |
| 772 | { |
| 773 | struct msm_hsic_hcd *mehci = |
| 774 | container_of(w, struct msm_hsic_hcd, bus_vote_w); |
| 775 | int ret; |
| 776 | |
| 777 | ret = msm_bus_scale_client_update_request(mehci->bus_perf_client, |
| 778 | mehci->bus_vote); |
| 779 | if (ret) |
| 780 | dev_err(mehci->dev, "%s: Failed to vote for bus bandwidth %d\n", |
| 781 | __func__, ret); |
| 782 | } |
| 783 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 784 | static irqreturn_t msm_hsic_irq(struct usb_hcd *hcd) |
| 785 | { |
| 786 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 787 | |
| 788 | if (atomic_read(&mehci->in_lpm)) { |
| 789 | disable_irq_nosync(hcd->irq); |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 790 | mehci->irq_enabled = false; |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 791 | dev_dbg(mehci->dev, "phy async intr\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 792 | mehci->async_int = true; |
| 793 | pm_runtime_get(mehci->dev); |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 794 | pm_stay_awake(mehci->dev); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 795 | return IRQ_HANDLED; |
| 796 | } |
| 797 | |
| 798 | return ehci_irq(hcd); |
| 799 | } |
| 800 | |
| 801 | static int ehci_hsic_reset(struct usb_hcd *hcd) |
| 802 | { |
| 803 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 804 | int retval; |
| 805 | |
| 806 | ehci->caps = USB_CAPLENGTH; |
| 807 | ehci->regs = USB_CAPLENGTH + |
| 808 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 809 | dbg_hcs_params(ehci, "reset"); |
| 810 | dbg_hcc_params(ehci, "reset"); |
| 811 | |
| 812 | /* cache the data to minimize the chip reads*/ |
| 813 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 814 | |
| 815 | hcd->has_tt = 1; |
| 816 | ehci->sbrn = HCD_USB2; |
| 817 | |
| 818 | retval = ehci_halt(ehci); |
| 819 | if (retval) |
| 820 | return retval; |
| 821 | |
| 822 | /* data structure init */ |
| 823 | retval = ehci_init(hcd); |
| 824 | if (retval) |
| 825 | return retval; |
| 826 | |
| 827 | retval = ehci_reset(ehci); |
| 828 | if (retval) |
| 829 | return retval; |
| 830 | |
| 831 | /* bursts of unspecified length. */ |
| 832 | writel_relaxed(0, USB_AHBBURST); |
| 833 | /* Use the AHB transactor */ |
Vijayavardhan Vennapusa | 5f32d7a | 2012-03-14 16:30:26 +0530 | [diff] [blame] | 834 | writel_relaxed(0x08, USB_AHBMODE); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 835 | /* Disable streaming mode and select host mode */ |
| 836 | writel_relaxed(0x13, USB_USBMODE); |
| 837 | |
| 838 | ehci_port_power(ehci, 1); |
| 839 | return 0; |
| 840 | } |
| 841 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 842 | static int ehci_hsic_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 843 | gfp_t mem_flags) |
| 844 | { |
| 845 | dbg_log_event(urb, event_to_str(URB_SUBMIT), 0); |
| 846 | return ehci_urb_enqueue(hcd, urb, mem_flags); |
| 847 | } |
| 848 | |
| 849 | static int ehci_hsic_bus_suspend(struct usb_hcd *hcd) |
| 850 | { |
| 851 | dbg_log_event(NULL, "Suspend RH", 0); |
| 852 | return ehci_bus_suspend(hcd); |
| 853 | } |
| 854 | |
| 855 | static int ehci_hsic_bus_resume(struct usb_hcd *hcd) |
| 856 | { |
| 857 | dbg_log_event(NULL, "Resume RH", 0); |
| 858 | return ehci_bus_resume(hcd); |
| 859 | } |
| 860 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 861 | static struct hc_driver msm_hsic_driver = { |
| 862 | .description = hcd_name, |
| 863 | .product_desc = "Qualcomm EHCI Host Controller using HSIC", |
| 864 | .hcd_priv_size = sizeof(struct msm_hsic_hcd), |
| 865 | |
| 866 | /* |
| 867 | * generic hardware linkage |
| 868 | */ |
| 869 | .irq = msm_hsic_irq, |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 870 | .flags = HCD_USB2 | HCD_MEMORY | HCD_OLD_ENUM, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 871 | |
| 872 | .reset = ehci_hsic_reset, |
| 873 | .start = ehci_run, |
| 874 | |
| 875 | .stop = ehci_stop, |
| 876 | .shutdown = ehci_shutdown, |
| 877 | |
| 878 | /* |
| 879 | * managing i/o requests and associated device resources |
| 880 | */ |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 881 | .urb_enqueue = ehci_hsic_urb_enqueue, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 882 | .urb_dequeue = ehci_urb_dequeue, |
| 883 | .endpoint_disable = ehci_endpoint_disable, |
| 884 | .endpoint_reset = ehci_endpoint_reset, |
| 885 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 886 | |
| 887 | /* |
| 888 | * scheduling support |
| 889 | */ |
| 890 | .get_frame_number = ehci_get_frame, |
| 891 | |
| 892 | /* |
| 893 | * root hub support |
| 894 | */ |
| 895 | .hub_status_data = ehci_hub_status_data, |
| 896 | .hub_control = ehci_hub_control, |
| 897 | .relinquish_port = ehci_relinquish_port, |
| 898 | .port_handed_over = ehci_port_handed_over, |
| 899 | |
| 900 | /* |
| 901 | * PM support |
| 902 | */ |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 903 | .bus_suspend = ehci_hsic_bus_suspend, |
| 904 | .bus_resume = ehci_hsic_bus_resume, |
| 905 | |
| 906 | .log_urb_complete = dbg_log_event, |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 907 | .dump_regs = dump_hsic_regs, |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 908 | |
| 909 | .enable_ulpi_control = ehci_msm_enable_ulpi_control, |
| 910 | .disable_ulpi_control = ehci_msm_disable_ulpi_control, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 911 | }; |
| 912 | |
| 913 | static int msm_hsic_init_clocks(struct msm_hsic_hcd *mehci, u32 init) |
| 914 | { |
| 915 | int ret = 0; |
| 916 | |
| 917 | if (!init) |
| 918 | goto put_clocks; |
| 919 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 920 | /*core_clk is required for LINK protocol engine |
| 921 | *clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 922 | mehci->core_clk = clk_get(mehci->dev, "core_clk"); |
| 923 | if (IS_ERR(mehci->core_clk)) { |
| 924 | dev_err(mehci->dev, "failed to get core_clk\n"); |
| 925 | ret = PTR_ERR(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 926 | return ret; |
| 927 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 928 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 929 | /* alt_core_clk is for LINK to be used during PHY RESET |
| 930 | * clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 931 | mehci->alt_core_clk = clk_get(mehci->dev, "alt_core_clk"); |
| 932 | if (IS_ERR(mehci->alt_core_clk)) { |
| 933 | dev_err(mehci->dev, "failed to core_clk\n"); |
| 934 | ret = PTR_ERR(mehci->alt_core_clk); |
| 935 | goto put_core_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 936 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 937 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 938 | /* phy_clk is required for HSIC PHY operation |
| 939 | * clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 940 | mehci->phy_clk = clk_get(mehci->dev, "phy_clk"); |
| 941 | if (IS_ERR(mehci->phy_clk)) { |
| 942 | dev_err(mehci->dev, "failed to get phy_clk\n"); |
| 943 | ret = PTR_ERR(mehci->phy_clk); |
| 944 | goto put_alt_core_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 945 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 946 | |
| 947 | /* 10MHz cal_clk is required for calibration of I/O pads */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 948 | mehci->cal_clk = clk_get(mehci->dev, "cal_clk"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 949 | if (IS_ERR(mehci->cal_clk)) { |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 950 | dev_err(mehci->dev, "failed to get cal_clk\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 951 | ret = PTR_ERR(mehci->cal_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 952 | goto put_phy_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 953 | } |
| 954 | clk_set_rate(mehci->cal_clk, 10000000); |
| 955 | |
| 956 | /* ahb_clk is required for data transfers */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 957 | mehci->ahb_clk = clk_get(mehci->dev, "iface_clk"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 958 | if (IS_ERR(mehci->ahb_clk)) { |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 959 | dev_err(mehci->dev, "failed to get iface_clk\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 960 | ret = PTR_ERR(mehci->ahb_clk); |
| 961 | goto put_cal_clk; |
| 962 | } |
| 963 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 964 | clk_prepare_enable(mehci->core_clk); |
| 965 | clk_prepare_enable(mehci->phy_clk); |
| 966 | clk_prepare_enable(mehci->cal_clk); |
| 967 | clk_prepare_enable(mehci->ahb_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 968 | |
| 969 | return 0; |
| 970 | |
| 971 | put_clocks: |
Jack Pham | fd193eb | 2012-02-22 15:38:08 -0800 | [diff] [blame] | 972 | if (!atomic_read(&mehci->in_lpm)) { |
| 973 | clk_disable_unprepare(mehci->core_clk); |
| 974 | clk_disable_unprepare(mehci->phy_clk); |
| 975 | clk_disable_unprepare(mehci->cal_clk); |
| 976 | clk_disable_unprepare(mehci->ahb_clk); |
| 977 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 978 | clk_put(mehci->ahb_clk); |
| 979 | put_cal_clk: |
| 980 | clk_put(mehci->cal_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 981 | put_phy_clk: |
| 982 | clk_put(mehci->phy_clk); |
| 983 | put_alt_core_clk: |
| 984 | clk_put(mehci->alt_core_clk); |
| 985 | put_core_clk: |
| 986 | clk_put(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 987 | |
| 988 | return ret; |
| 989 | } |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 990 | static irqreturn_t hsic_peripheral_status_change(int irq, void *dev_id) |
| 991 | { |
| 992 | struct msm_hsic_hcd *mehci = dev_id; |
| 993 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 994 | pr_debug("%s: mehci:%p dev_id:%p\n", __func__, mehci, dev_id); |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 995 | |
| 996 | if (mehci) |
| 997 | msm_hsic_config_gpios(mehci, 0); |
| 998 | |
| 999 | return IRQ_HANDLED; |
| 1000 | } |
| 1001 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1002 | static irqreturn_t msm_hsic_wakeup_irq(int irq, void *data) |
| 1003 | { |
| 1004 | struct msm_hsic_hcd *mehci = data; |
| 1005 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1006 | mehci->wakeup_int_cnt++; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1007 | dbg_log_event(NULL, "Remote Wakeup IRQ", mehci->wakeup_int_cnt); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1008 | dev_dbg(mehci->dev, "%s: hsic remote wakeup interrupt cnt: %u\n", |
| 1009 | __func__, mehci->wakeup_int_cnt); |
| 1010 | |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 1011 | mehci->async_int = true; |
| 1012 | pm_runtime_get(mehci->dev); |
| 1013 | pm_stay_awake(mehci->dev); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1014 | |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1015 | if (mehci->wakeup_irq_enabled) { |
| 1016 | mehci->wakeup_irq_enabled = 0; |
| 1017 | disable_irq_wake(irq); |
| 1018 | disable_irq_nosync(irq); |
| 1019 | } |
| 1020 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1021 | return IRQ_HANDLED; |
| 1022 | } |
| 1023 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1024 | static int ehci_hsic_msm_bus_show(struct seq_file *s, void *unused) |
| 1025 | { |
| 1026 | if (debug_bus_voting_enabled) |
| 1027 | seq_printf(s, "enabled\n"); |
| 1028 | else |
| 1029 | seq_printf(s, "disabled\n"); |
| 1030 | |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | static int ehci_hsic_msm_bus_open(struct inode *inode, struct file *file) |
| 1035 | { |
| 1036 | return single_open(file, ehci_hsic_msm_bus_show, inode->i_private); |
| 1037 | } |
| 1038 | |
| 1039 | static ssize_t ehci_hsic_msm_bus_write(struct file *file, |
| 1040 | const char __user *ubuf, size_t count, loff_t *ppos) |
| 1041 | { |
| 1042 | char buf[8]; |
| 1043 | int ret; |
| 1044 | struct seq_file *s = file->private_data; |
| 1045 | struct msm_hsic_hcd *mehci = s->private; |
| 1046 | |
| 1047 | memset(buf, 0x00, sizeof(buf)); |
| 1048 | |
| 1049 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 1050 | return -EFAULT; |
| 1051 | |
| 1052 | if (!strncmp(buf, "enable", 6)) { |
| 1053 | /* Do not vote here. Let hsic driver decide when to vote */ |
| 1054 | debug_bus_voting_enabled = true; |
| 1055 | } else { |
| 1056 | debug_bus_voting_enabled = false; |
| 1057 | if (mehci->bus_perf_client) { |
| 1058 | ret = msm_bus_scale_client_update_request( |
| 1059 | mehci->bus_perf_client, 0); |
| 1060 | if (ret) |
| 1061 | dev_err(mehci->dev, "%s: Failed to devote " |
| 1062 | "for bus bw %d\n", __func__, ret); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | return count; |
| 1067 | } |
| 1068 | |
| 1069 | const struct file_operations ehci_hsic_msm_bus_fops = { |
| 1070 | .open = ehci_hsic_msm_bus_open, |
| 1071 | .read = seq_read, |
| 1072 | .write = ehci_hsic_msm_bus_write, |
| 1073 | .llseek = seq_lseek, |
| 1074 | .release = single_release, |
| 1075 | }; |
| 1076 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1077 | static int ehci_hsic_msm_wakeup_cnt_show(struct seq_file *s, void *unused) |
| 1078 | { |
| 1079 | struct msm_hsic_hcd *mehci = s->private; |
| 1080 | |
| 1081 | seq_printf(s, "%u\n", mehci->wakeup_int_cnt); |
| 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | static int ehci_hsic_msm_wakeup_cnt_open(struct inode *inode, struct file *f) |
| 1087 | { |
| 1088 | return single_open(f, ehci_hsic_msm_wakeup_cnt_show, inode->i_private); |
| 1089 | } |
| 1090 | |
| 1091 | const struct file_operations ehci_hsic_msm_wakeup_cnt_fops = { |
| 1092 | .open = ehci_hsic_msm_wakeup_cnt_open, |
| 1093 | .read = seq_read, |
| 1094 | .llseek = seq_lseek, |
| 1095 | .release = single_release, |
| 1096 | }; |
| 1097 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1098 | static int ehci_hsic_msm_data_events_show(struct seq_file *s, void *unused) |
| 1099 | { |
| 1100 | unsigned long flags; |
| 1101 | unsigned i; |
| 1102 | |
| 1103 | read_lock_irqsave(&dbg_hsic_data.lck, flags); |
| 1104 | |
| 1105 | i = dbg_hsic_data.idx; |
| 1106 | for (dbg_inc(&i); i != dbg_hsic_data.idx; dbg_inc(&i)) { |
| 1107 | if (!strnlen(dbg_hsic_data.buf[i], DBG_MSG_LEN)) |
| 1108 | continue; |
| 1109 | seq_printf(s, "%s\n", dbg_hsic_data.buf[i]); |
| 1110 | } |
| 1111 | |
| 1112 | read_unlock_irqrestore(&dbg_hsic_data.lck, flags); |
| 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
| 1117 | static int ehci_hsic_msm_data_events_open(struct inode *inode, struct file *f) |
| 1118 | { |
| 1119 | return single_open(f, ehci_hsic_msm_data_events_show, inode->i_private); |
| 1120 | } |
| 1121 | |
| 1122 | const struct file_operations ehci_hsic_msm_dbg_data_fops = { |
| 1123 | .open = ehci_hsic_msm_data_events_open, |
| 1124 | .read = seq_read, |
| 1125 | .llseek = seq_lseek, |
| 1126 | .release = single_release, |
| 1127 | }; |
| 1128 | |
| 1129 | static int ehci_hsic_msm_ctrl_events_show(struct seq_file *s, void *unused) |
| 1130 | { |
| 1131 | unsigned long flags; |
| 1132 | unsigned i; |
| 1133 | |
| 1134 | read_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 1135 | |
| 1136 | i = dbg_hsic_ctrl.idx; |
| 1137 | for (dbg_inc(&i); i != dbg_hsic_ctrl.idx; dbg_inc(&i)) { |
| 1138 | if (!strnlen(dbg_hsic_ctrl.buf[i], DBG_MSG_LEN)) |
| 1139 | continue; |
| 1140 | seq_printf(s, "%s\n", dbg_hsic_ctrl.buf[i]); |
| 1141 | } |
| 1142 | |
| 1143 | read_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 1144 | |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
| 1148 | static int ehci_hsic_msm_ctrl_events_open(struct inode *inode, struct file *f) |
| 1149 | { |
| 1150 | return single_open(f, ehci_hsic_msm_ctrl_events_show, inode->i_private); |
| 1151 | } |
| 1152 | |
| 1153 | const struct file_operations ehci_hsic_msm_dbg_ctrl_fops = { |
| 1154 | .open = ehci_hsic_msm_ctrl_events_open, |
| 1155 | .read = seq_read, |
| 1156 | .llseek = seq_lseek, |
| 1157 | .release = single_release, |
| 1158 | }; |
| 1159 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1160 | static struct dentry *ehci_hsic_msm_dbg_root; |
| 1161 | static int ehci_hsic_msm_debugfs_init(struct msm_hsic_hcd *mehci) |
| 1162 | { |
| 1163 | struct dentry *ehci_hsic_msm_dentry; |
| 1164 | |
| 1165 | ehci_hsic_msm_dbg_root = debugfs_create_dir("ehci_hsic_msm_dbg", NULL); |
| 1166 | |
| 1167 | if (!ehci_hsic_msm_dbg_root || IS_ERR(ehci_hsic_msm_dbg_root)) |
| 1168 | return -ENODEV; |
| 1169 | |
| 1170 | ehci_hsic_msm_dentry = debugfs_create_file("bus_voting", |
| 1171 | S_IRUGO | S_IWUSR, |
| 1172 | ehci_hsic_msm_dbg_root, mehci, |
| 1173 | &ehci_hsic_msm_bus_fops); |
| 1174 | |
| 1175 | if (!ehci_hsic_msm_dentry) { |
| 1176 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1177 | return -ENODEV; |
| 1178 | } |
| 1179 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1180 | ehci_hsic_msm_dentry = debugfs_create_file("wakeup_cnt", |
| 1181 | S_IRUGO, |
| 1182 | ehci_hsic_msm_dbg_root, mehci, |
| 1183 | &ehci_hsic_msm_wakeup_cnt_fops); |
| 1184 | |
| 1185 | if (!ehci_hsic_msm_dentry) { |
| 1186 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1187 | return -ENODEV; |
| 1188 | } |
| 1189 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1190 | ehci_hsic_msm_dentry = debugfs_create_file("show_ctrl_events", |
| 1191 | S_IRUGO, |
| 1192 | ehci_hsic_msm_dbg_root, mehci, |
| 1193 | &ehci_hsic_msm_dbg_ctrl_fops); |
| 1194 | |
| 1195 | if (!ehci_hsic_msm_dentry) { |
| 1196 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1197 | return -ENODEV; |
| 1198 | } |
| 1199 | |
| 1200 | ehci_hsic_msm_dentry = debugfs_create_file("show_data_events", |
| 1201 | S_IRUGO, |
| 1202 | ehci_hsic_msm_dbg_root, mehci, |
| 1203 | &ehci_hsic_msm_dbg_data_fops); |
| 1204 | |
| 1205 | if (!ehci_hsic_msm_dentry) { |
| 1206 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1207 | return -ENODEV; |
| 1208 | } |
| 1209 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1210 | return 0; |
| 1211 | } |
| 1212 | |
| 1213 | static void ehci_hsic_msm_debugfs_cleanup(void) |
| 1214 | { |
| 1215 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1216 | } |
| 1217 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1218 | static int __devinit ehci_hsic_msm_probe(struct platform_device *pdev) |
| 1219 | { |
| 1220 | struct usb_hcd *hcd; |
| 1221 | struct resource *res; |
| 1222 | struct msm_hsic_hcd *mehci; |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 1223 | struct msm_hsic_host_platform_data *pdata; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1224 | int ret; |
| 1225 | |
| 1226 | dev_dbg(&pdev->dev, "ehci_msm-hsic probe\n"); |
| 1227 | |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1228 | /* After parent device's probe is executed, it will be put in suspend |
| 1229 | * mode. When child device's probe is called, driver core is not |
| 1230 | * resuming parent device due to which parent will be in suspend even |
| 1231 | * though child is active. Hence resume the parent device explicitly. |
| 1232 | */ |
| 1233 | if (pdev->dev.parent) |
| 1234 | pm_runtime_get_sync(pdev->dev.parent); |
| 1235 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1236 | hcd = usb_create_hcd(&msm_hsic_driver, &pdev->dev, |
| 1237 | dev_name(&pdev->dev)); |
| 1238 | if (!hcd) { |
| 1239 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
| 1240 | return -ENOMEM; |
| 1241 | } |
| 1242 | |
| 1243 | hcd->irq = platform_get_irq(pdev, 0); |
| 1244 | if (hcd->irq < 0) { |
| 1245 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); |
| 1246 | ret = hcd->irq; |
| 1247 | goto put_hcd; |
| 1248 | } |
| 1249 | |
| 1250 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1251 | if (!res) { |
| 1252 | dev_err(&pdev->dev, "Unable to get memory resource\n"); |
| 1253 | ret = -ENODEV; |
| 1254 | goto put_hcd; |
| 1255 | } |
| 1256 | |
| 1257 | hcd->rsrc_start = res->start; |
| 1258 | hcd->rsrc_len = resource_size(res); |
| 1259 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 1260 | if (!hcd->regs) { |
| 1261 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 1262 | ret = -ENOMEM; |
| 1263 | goto put_hcd; |
| 1264 | } |
| 1265 | |
| 1266 | mehci = hcd_to_hsic(hcd); |
| 1267 | mehci->dev = &pdev->dev; |
| 1268 | |
Hemant Kumar | 38ce5d8 | 2012-05-29 13:00:58 -0700 | [diff] [blame] | 1269 | mehci->ehci.susp_sof_bug = 1; |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 1270 | mehci->ehci.reset_sof_bug = 1; |
Hemant Kumar | 38ce5d8 | 2012-05-29 13:00:58 -0700 | [diff] [blame] | 1271 | |
Hemant Kumar | e404049 | 2012-06-21 17:35:42 -0700 | [diff] [blame] | 1272 | mehci->ehci.resume_sof_bug = 1; |
| 1273 | |
Hemant Kumar | 933e040 | 2012-05-22 11:11:40 -0700 | [diff] [blame] | 1274 | mehci->ehci.max_log2_irq_thresh = 6; |
| 1275 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1276 | res = platform_get_resource_byname(pdev, |
| 1277 | IORESOURCE_IRQ, |
| 1278 | "peripheral_status_irq"); |
| 1279 | if (res) |
| 1280 | mehci->peripheral_status_irq = res->start; |
| 1281 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1282 | res = platform_get_resource_byname(pdev, IORESOURCE_IO, "wakeup"); |
| 1283 | if (res) { |
| 1284 | mehci->wakeup_gpio = res->start; |
| 1285 | mehci->wakeup_irq = MSM_GPIO_TO_INT(res->start); |
| 1286 | dev_dbg(mehci->dev, "wakeup_irq: %d\n", mehci->wakeup_irq); |
| 1287 | } |
| 1288 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1289 | ret = msm_hsic_init_clocks(mehci, 1); |
| 1290 | if (ret) { |
| 1291 | dev_err(&pdev->dev, "unable to initialize clocks\n"); |
| 1292 | ret = -ENODEV; |
| 1293 | goto unmap; |
| 1294 | } |
| 1295 | |
| 1296 | ret = msm_hsic_init_vddcx(mehci, 1); |
| 1297 | if (ret) { |
| 1298 | dev_err(&pdev->dev, "unable to initialize VDDCX\n"); |
| 1299 | ret = -ENODEV; |
| 1300 | goto deinit_clocks; |
| 1301 | } |
| 1302 | |
| 1303 | ret = msm_hsic_reset(mehci); |
| 1304 | if (ret) { |
| 1305 | dev_err(&pdev->dev, "unable to initialize PHY\n"); |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1306 | goto deinit_vddcx; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1307 | } |
| 1308 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 1309 | ehci_wq = create_singlethread_workqueue("ehci_wq"); |
| 1310 | if (!ehci_wq) { |
| 1311 | dev_err(&pdev->dev, "unable to create workqueue\n"); |
| 1312 | ret = -ENOMEM; |
| 1313 | goto deinit_vddcx; |
| 1314 | } |
| 1315 | |
| 1316 | INIT_WORK(&mehci->bus_vote_w, ehci_hsic_bus_vote_w); |
| 1317 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1318 | ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
| 1319 | if (ret) { |
| 1320 | dev_err(&pdev->dev, "unable to register HCD\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1321 | goto unconfig_gpio; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1322 | } |
| 1323 | |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 1324 | mehci->irq_enabled = true; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1325 | device_init_wakeup(&pdev->dev, 1); |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1326 | |
| 1327 | if (mehci->peripheral_status_irq) { |
| 1328 | ret = request_threaded_irq(mehci->peripheral_status_irq, |
| 1329 | NULL, hsic_peripheral_status_change, |
| 1330 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
| 1331 | | IRQF_SHARED, |
| 1332 | "hsic_peripheral_status", mehci); |
| 1333 | if (ret) |
| 1334 | dev_err(&pdev->dev, "%s:request_irq:%d failed:%d", |
| 1335 | __func__, mehci->peripheral_status_irq, ret); |
| 1336 | } |
| 1337 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1338 | /* configure wakeup irq */ |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1339 | if (mehci->wakeup_irq) { |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1340 | ret = request_irq(mehci->wakeup_irq, msm_hsic_wakeup_irq, |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1341 | IRQF_TRIGGER_HIGH, |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1342 | "msm_hsic_wakeup", mehci); |
| 1343 | if (!ret) { |
| 1344 | disable_irq_nosync(mehci->wakeup_irq); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1345 | } else { |
| 1346 | dev_err(&pdev->dev, "request_irq(%d) failed: %d\n", |
| 1347 | mehci->wakeup_irq, ret); |
| 1348 | mehci->wakeup_irq = 0; |
| 1349 | } |
| 1350 | } |
| 1351 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1352 | ret = ehci_hsic_msm_debugfs_init(mehci); |
| 1353 | if (ret) |
| 1354 | dev_dbg(&pdev->dev, "mode debugfs file is" |
| 1355 | "not available\n"); |
| 1356 | |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1357 | pdata = mehci->dev->platform_data; |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1358 | if (pdata && pdata->bus_scale_table) { |
| 1359 | mehci->bus_perf_client = |
| 1360 | msm_bus_scale_register_client(pdata->bus_scale_table); |
| 1361 | /* Configure BUS performance parameters for MAX bandwidth */ |
| 1362 | if (mehci->bus_perf_client) { |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 1363 | mehci->bus_vote = true; |
| 1364 | queue_work(ehci_wq, &mehci->bus_vote_w); |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1365 | } else { |
| 1366 | dev_err(&pdev->dev, "%s: Failed to register BUS " |
| 1367 | "scaling client!!\n", __func__); |
| 1368 | } |
| 1369 | } |
| 1370 | |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 1371 | __mehci = mehci; |
| 1372 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1373 | /* |
| 1374 | * This pdev->dev is assigned parent of root-hub by USB core, |
| 1375 | * hence, runtime framework automatically calls this driver's |
| 1376 | * runtime APIs based on root-hub's state. |
| 1377 | */ |
| 1378 | pm_runtime_set_active(&pdev->dev); |
| 1379 | pm_runtime_enable(&pdev->dev); |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1380 | /* Decrement the parent device's counter after probe. |
| 1381 | * As child is active, parent will not be put into |
| 1382 | * suspend mode. |
| 1383 | */ |
| 1384 | if (pdev->dev.parent) |
| 1385 | pm_runtime_put_sync(pdev->dev.parent); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1386 | |
| 1387 | return 0; |
| 1388 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1389 | unconfig_gpio: |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 1390 | destroy_workqueue(ehci_wq); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1391 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1392 | deinit_vddcx: |
| 1393 | msm_hsic_init_vddcx(mehci, 0); |
| 1394 | deinit_clocks: |
| 1395 | msm_hsic_init_clocks(mehci, 0); |
| 1396 | unmap: |
| 1397 | iounmap(hcd->regs); |
| 1398 | put_hcd: |
| 1399 | usb_put_hcd(hcd); |
| 1400 | |
| 1401 | return ret; |
| 1402 | } |
| 1403 | |
| 1404 | static int __devexit ehci_hsic_msm_remove(struct platform_device *pdev) |
| 1405 | { |
| 1406 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 1407 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1408 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1409 | if (mehci->peripheral_status_irq) |
| 1410 | free_irq(mehci->peripheral_status_irq, mehci); |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1411 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1412 | if (mehci->wakeup_irq) { |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1413 | if (mehci->wakeup_irq_enabled) |
| 1414 | disable_irq_wake(mehci->wakeup_irq); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1415 | free_irq(mehci->wakeup_irq, mehci); |
| 1416 | } |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1417 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 1418 | /* |
| 1419 | * If the update request is called after unregister, the request will |
| 1420 | * fail. Results are undefined if unregister is called in the middle of |
| 1421 | * update request. |
| 1422 | */ |
| 1423 | mehci->bus_vote = false; |
| 1424 | cancel_work_sync(&mehci->bus_vote_w); |
| 1425 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1426 | if (mehci->bus_perf_client) |
| 1427 | msm_bus_scale_unregister_client(mehci->bus_perf_client); |
| 1428 | |
| 1429 | ehci_hsic_msm_debugfs_cleanup(); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1430 | device_init_wakeup(&pdev->dev, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1431 | pm_runtime_set_suspended(&pdev->dev); |
| 1432 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame^] | 1433 | destroy_workqueue(ehci_wq); |
| 1434 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1435 | usb_remove_hcd(hcd); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1436 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1437 | msm_hsic_init_vddcx(mehci, 0); |
| 1438 | |
| 1439 | msm_hsic_init_clocks(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1440 | iounmap(hcd->regs); |
| 1441 | usb_put_hcd(hcd); |
| 1442 | |
| 1443 | return 0; |
| 1444 | } |
| 1445 | |
| 1446 | #ifdef CONFIG_PM_SLEEP |
| 1447 | static int msm_hsic_pm_suspend(struct device *dev) |
| 1448 | { |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 1449 | int ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1450 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1451 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1452 | |
| 1453 | dev_dbg(dev, "ehci-msm-hsic PM suspend\n"); |
| 1454 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1455 | dbg_log_event(NULL, "PM Suspend", 0); |
| 1456 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1457 | if (device_may_wakeup(dev)) |
| 1458 | enable_irq_wake(hcd->irq); |
| 1459 | |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 1460 | ret = msm_hsic_suspend(mehci); |
| 1461 | |
| 1462 | if (ret && device_may_wakeup(dev)) |
| 1463 | disable_irq_wake(hcd->irq); |
| 1464 | |
| 1465 | return ret; |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1466 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1467 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1468 | static int msm_hsic_pm_resume(struct device *dev) |
| 1469 | { |
| 1470 | int ret; |
| 1471 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1472 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1473 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1474 | dbg_log_event(NULL, "PM Resume", 0); |
| 1475 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1476 | if (device_may_wakeup(dev)) |
| 1477 | disable_irq_wake(hcd->irq); |
| 1478 | |
| 1479 | ret = msm_hsic_resume(mehci); |
| 1480 | if (ret) |
| 1481 | return ret; |
| 1482 | |
| 1483 | /* Bring the device to full powered state upon system resume */ |
| 1484 | pm_runtime_disable(dev); |
| 1485 | pm_runtime_set_active(dev); |
| 1486 | pm_runtime_enable(dev); |
| 1487 | |
| 1488 | return 0; |
| 1489 | } |
| 1490 | #endif |
| 1491 | |
| 1492 | #ifdef CONFIG_PM_RUNTIME |
| 1493 | static int msm_hsic_runtime_idle(struct device *dev) |
| 1494 | { |
| 1495 | dev_dbg(dev, "EHCI runtime idle\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1496 | return 0; |
| 1497 | } |
| 1498 | |
| 1499 | static int msm_hsic_runtime_suspend(struct device *dev) |
| 1500 | { |
| 1501 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1502 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1503 | |
| 1504 | dev_dbg(dev, "EHCI runtime suspend\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1505 | |
| 1506 | dbg_log_event(NULL, "Run Time PM Suspend", 0); |
| 1507 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1508 | return msm_hsic_suspend(mehci); |
| 1509 | } |
| 1510 | |
| 1511 | static int msm_hsic_runtime_resume(struct device *dev) |
| 1512 | { |
| 1513 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1514 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1515 | |
| 1516 | dev_dbg(dev, "EHCI runtime resume\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1517 | |
| 1518 | dbg_log_event(NULL, "Run Time PM Resume", 0); |
| 1519 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1520 | return msm_hsic_resume(mehci); |
| 1521 | } |
| 1522 | #endif |
| 1523 | |
| 1524 | #ifdef CONFIG_PM |
| 1525 | static const struct dev_pm_ops msm_hsic_dev_pm_ops = { |
| 1526 | SET_SYSTEM_SLEEP_PM_OPS(msm_hsic_pm_suspend, msm_hsic_pm_resume) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1527 | SET_RUNTIME_PM_OPS(msm_hsic_runtime_suspend, msm_hsic_runtime_resume, |
| 1528 | msm_hsic_runtime_idle) |
| 1529 | }; |
| 1530 | #endif |
| 1531 | |
| 1532 | static struct platform_driver ehci_msm_hsic_driver = { |
| 1533 | .probe = ehci_hsic_msm_probe, |
| 1534 | .remove = __devexit_p(ehci_hsic_msm_remove), |
| 1535 | .driver = { |
| 1536 | .name = "msm_hsic_host", |
| 1537 | #ifdef CONFIG_PM |
| 1538 | .pm = &msm_hsic_dev_pm_ops, |
| 1539 | #endif |
| 1540 | }, |
| 1541 | }; |