ehci-msm2.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  1. /* ehci-msm2.c - HSUSB Host Controller Driver Implementation
  2. *
  3. * Copyright (c) 2008-2013, The Linux Foundation. All rights reserved.
  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. #include <linux/platform_device.h>
  25. #include <linux/clk.h>
  26. #include <linux/err.h>
  27. #include <linux/pm_wakeup.h>
  28. #include <linux/pm_runtime.h>
  29. #include <linux/regulator/consumer.h>
  30. #include <linux/gpio.h>
  31. #include <linux/of_gpio.h>
  32. #include <linux/irq.h>
  33. #include <linux/usb/ulpi.h>
  34. #include <linux/usb/msm_hsusb_hw.h>
  35. #include <linux/usb/msm_hsusb.h>
  36. #include <linux/of.h>
  37. #include <mach/clk.h>
  38. #include <mach/msm_xo.h>
  39. #include <mach/msm_iomap.h>
  40. #include <linux/debugfs.h>
  41. #include <mach/rpm-regulator.h>
  42. #define MSM_USB_BASE (hcd->regs)
  43. #define PDEV_NAME_LEN 20
  44. static bool uicc_card_present;
  45. module_param(uicc_card_present, bool, S_IRUGO | S_IWUSR);
  46. MODULE_PARM_DESC(uicc_card_present, "UICC card inserted");
  47. struct msm_hcd {
  48. struct ehci_hcd ehci;
  49. spinlock_t wakeup_lock;
  50. struct device *dev;
  51. struct clk *xo_clk;
  52. struct clk *iface_clk;
  53. struct clk *core_clk;
  54. struct clk *alt_core_clk;
  55. struct clk *phy_sleep_clk;
  56. struct regulator *hsusb_vddcx;
  57. struct regulator *hsusb_3p3;
  58. struct regulator *hsusb_1p8;
  59. struct regulator *vbus;
  60. struct msm_xo_voter *xo_handle;
  61. bool async_int;
  62. bool vbus_on;
  63. atomic_t in_lpm;
  64. int pmic_gpio_dp_irq;
  65. bool pmic_gpio_dp_irq_enabled;
  66. uint32_t pmic_gpio_int_cnt;
  67. atomic_t pm_usage_cnt;
  68. struct wakeup_source ws;
  69. struct work_struct phy_susp_fail_work;
  70. int async_irq;
  71. bool async_irq_enabled;
  72. uint32_t async_int_cnt;
  73. int resume_gpio;
  74. int wakeup_int_cnt;
  75. bool wakeup_irq_enabled;
  76. int wakeup_irq;
  77. enum usb_vdd_type vdd_type;
  78. void __iomem *usb_phy_ctrl_reg;
  79. };
  80. static inline struct msm_hcd *hcd_to_mhcd(struct usb_hcd *hcd)
  81. {
  82. return (struct msm_hcd *) (hcd->hcd_priv);
  83. }
  84. static inline struct usb_hcd *mhcd_to_hcd(struct msm_hcd *mhcd)
  85. {
  86. return container_of((void *) mhcd, struct usb_hcd, hcd_priv);
  87. }
  88. #define HSUSB_PHY_3P3_VOL_MIN 3050000 /* uV */
  89. #define HSUSB_PHY_3P3_VOL_MAX 3300000 /* uV */
  90. #define HSUSB_PHY_3P3_HPM_LOAD 50000 /* uA */
  91. #define HSUSB_PHY_1P8_VOL_MIN 1800000 /* uV */
  92. #define HSUSB_PHY_1P8_VOL_MAX 1800000 /* uV */
  93. #define HSUSB_PHY_1P8_HPM_LOAD 50000 /* uA */
  94. #define HSUSB_PHY_VDD_DIG_VOL_NONE 0 /* uV */
  95. #define HSUSB_PHY_VDD_DIG_VOL_MIN 1045000 /* uV */
  96. #define HSUSB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */
  97. #define HSUSB_PHY_VDD_DIG_LOAD 49360 /* uA */
  98. #define HSUSB_PHY_SUSP_DIG_VOL_P50 500000
  99. #define HSUSB_PHY_SUSP_DIG_VOL_P75 750000
  100. enum hsusb_vdd_value {
  101. VDD_MIN_NONE = 0,
  102. VDD_MIN_P50,
  103. VDD_MIN_P75,
  104. VDD_MIN_OP,
  105. VDD_MAX_OP,
  106. VDD_VAL_MAX_OP,
  107. };
  108. static int hsusb_vdd_val[VDD_TYPE_MAX][VDD_VAL_MAX_OP] = {
  109. { /* VDD_CX CORNER Voting */
  110. [VDD_MIN_NONE] = RPM_VREG_CORNER_NONE,
  111. [VDD_MIN_P50] = RPM_VREG_CORNER_NONE,
  112. [VDD_MIN_P75] = RPM_VREG_CORNER_NONE,
  113. [VDD_MIN_OP] = RPM_VREG_CORNER_NOMINAL,
  114. [VDD_MAX_OP] = RPM_VREG_CORNER_HIGH,
  115. },
  116. { /* VDD_CX Voltage Voting */
  117. [VDD_MIN_NONE] = HSUSB_PHY_VDD_DIG_VOL_NONE,
  118. [VDD_MIN_P50] = HSUSB_PHY_SUSP_DIG_VOL_P50,
  119. [VDD_MIN_P75] = HSUSB_PHY_SUSP_DIG_VOL_P75,
  120. [VDD_MIN_OP] = HSUSB_PHY_VDD_DIG_VOL_MIN,
  121. [VDD_MAX_OP] = HSUSB_PHY_VDD_DIG_VOL_MAX,
  122. },
  123. };
  124. static int msm_ehci_init_vddcx(struct msm_hcd *mhcd, int init)
  125. {
  126. int ret = 0;
  127. int none_vol, min_vol, max_vol;
  128. u32 tmp[5];
  129. int len = 0;
  130. if (!init) {
  131. none_vol = hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_NONE];
  132. max_vol = hsusb_vdd_val[mhcd->vdd_type][VDD_MAX_OP];
  133. goto disable_reg;
  134. }
  135. mhcd->vdd_type = VDDCX_CORNER;
  136. mhcd->hsusb_vddcx = devm_regulator_get(mhcd->dev, "hsusb_vdd_dig");
  137. if (IS_ERR(mhcd->hsusb_vddcx)) {
  138. mhcd->hsusb_vddcx = devm_regulator_get(mhcd->dev,
  139. "HSUSB_VDDCX");
  140. if (IS_ERR(mhcd->hsusb_vddcx)) {
  141. dev_err(mhcd->dev, "unable to get ehci vddcx\n");
  142. return PTR_ERR(mhcd->hsusb_vddcx);
  143. }
  144. mhcd->vdd_type = VDDCX;
  145. }
  146. if (mhcd->dev->of_node) {
  147. of_get_property(mhcd->dev->of_node,
  148. "qcom,vdd-voltage-level",
  149. &len);
  150. if (len == sizeof(tmp)) {
  151. of_property_read_u32_array(mhcd->dev->of_node,
  152. "qcom,vdd-voltage-level",
  153. tmp, len/sizeof(*tmp));
  154. hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_NONE] = tmp[0];
  155. hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_P50] = tmp[1];
  156. hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_P75] = tmp[2];
  157. hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_OP] = tmp[3];
  158. hsusb_vdd_val[mhcd->vdd_type][VDD_MAX_OP] = tmp[4];
  159. } else {
  160. dev_dbg(mhcd->dev, "Use default vdd config\n");
  161. }
  162. }
  163. none_vol = hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_NONE];
  164. min_vol = hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_OP];
  165. max_vol = hsusb_vdd_val[mhcd->vdd_type][VDD_MAX_OP];
  166. ret = regulator_set_voltage(mhcd->hsusb_vddcx, min_vol, max_vol);
  167. if (ret) {
  168. dev_err(mhcd->dev, "unable to set the voltage"
  169. "for ehci vddcx\n");
  170. return ret;
  171. }
  172. ret = regulator_set_optimum_mode(mhcd->hsusb_vddcx,
  173. HSUSB_PHY_VDD_DIG_LOAD);
  174. if (ret < 0) {
  175. dev_err(mhcd->dev, "%s: Unable to set optimum mode of the"
  176. " regulator: VDDCX\n", __func__);
  177. goto reg_optimum_mode_err;
  178. }
  179. ret = regulator_enable(mhcd->hsusb_vddcx);
  180. if (ret) {
  181. dev_err(mhcd->dev, "unable to enable ehci vddcx\n");
  182. goto reg_enable_err;
  183. }
  184. return 0;
  185. disable_reg:
  186. regulator_disable(mhcd->hsusb_vddcx);
  187. reg_enable_err:
  188. regulator_set_optimum_mode(mhcd->hsusb_vddcx, 0);
  189. reg_optimum_mode_err:
  190. regulator_set_voltage(mhcd->hsusb_vddcx, none_vol, max_vol);
  191. return ret;
  192. }
  193. static int msm_ehci_ldo_init(struct msm_hcd *mhcd, int init)
  194. {
  195. int rc = 0;
  196. if (!init)
  197. goto put_1p8;
  198. mhcd->hsusb_3p3 = devm_regulator_get(mhcd->dev, "HSUSB_3p3");
  199. if (IS_ERR(mhcd->hsusb_3p3)) {
  200. dev_err(mhcd->dev, "unable to get hsusb 3p3\n");
  201. return PTR_ERR(mhcd->hsusb_3p3);
  202. }
  203. rc = regulator_set_voltage(mhcd->hsusb_3p3,
  204. HSUSB_PHY_3P3_VOL_MIN, HSUSB_PHY_3P3_VOL_MAX);
  205. if (rc) {
  206. dev_err(mhcd->dev, "unable to set voltage level for"
  207. "hsusb 3p3\n");
  208. return rc;
  209. }
  210. mhcd->hsusb_1p8 = devm_regulator_get(mhcd->dev, "HSUSB_1p8");
  211. if (IS_ERR(mhcd->hsusb_1p8)) {
  212. dev_err(mhcd->dev, "unable to get hsusb 1p8\n");
  213. rc = PTR_ERR(mhcd->hsusb_1p8);
  214. goto put_3p3_lpm;
  215. }
  216. rc = regulator_set_voltage(mhcd->hsusb_1p8,
  217. HSUSB_PHY_1P8_VOL_MIN, HSUSB_PHY_1P8_VOL_MAX);
  218. if (rc) {
  219. dev_err(mhcd->dev, "unable to set voltage level for"
  220. "hsusb 1p8\n");
  221. goto put_1p8;
  222. }
  223. return 0;
  224. put_1p8:
  225. regulator_set_voltage(mhcd->hsusb_1p8, 0, HSUSB_PHY_1P8_VOL_MAX);
  226. put_3p3_lpm:
  227. regulator_set_voltage(mhcd->hsusb_3p3, 0, HSUSB_PHY_3P3_VOL_MAX);
  228. return rc;
  229. }
  230. #ifdef CONFIG_PM_SLEEP
  231. static int msm_ehci_config_vddcx(struct msm_hcd *mhcd, int high)
  232. {
  233. struct msm_usb_host_platform_data *pdata;
  234. int max_vol = hsusb_vdd_val[mhcd->vdd_type][VDD_MAX_OP];
  235. int min_vol;
  236. int ret;
  237. pdata = mhcd->dev->platform_data;
  238. if (high)
  239. min_vol = hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_OP];
  240. else if (pdata && pdata->dock_connect_irq &&
  241. !irq_read_line(pdata->dock_connect_irq))
  242. min_vol = hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_P75];
  243. else
  244. min_vol = hsusb_vdd_val[mhcd->vdd_type][VDD_MIN_P50];
  245. ret = regulator_set_voltage(mhcd->hsusb_vddcx, min_vol, max_vol);
  246. if (ret) {
  247. dev_err(mhcd->dev, "%s: unable to set the voltage of regulator"
  248. " HSUSB_VDDCX\n", __func__);
  249. return ret;
  250. }
  251. dev_dbg(mhcd->dev, "%s: min_vol:%d max_vol:%d\n", __func__, min_vol,
  252. max_vol);
  253. return ret;
  254. }
  255. #else
  256. static int msm_ehci_config_vddcx(struct msm_hcd *mhcd, int high)
  257. {
  258. return 0;
  259. }
  260. #endif
  261. static void msm_ehci_vbus_power(struct msm_hcd *mhcd, bool on)
  262. {
  263. int ret;
  264. const struct msm_usb_host_platform_data *pdata;
  265. pdata = mhcd->dev->platform_data;
  266. if (pdata && pdata->is_uicc)
  267. return;
  268. if (!mhcd->vbus) {
  269. pr_err("vbus is NULL.");
  270. return;
  271. }
  272. if (mhcd->vbus_on == on)
  273. return;
  274. if (on) {
  275. ret = regulator_enable(mhcd->vbus);
  276. if (ret) {
  277. pr_err("unable to enable vbus\n");
  278. return;
  279. }
  280. mhcd->vbus_on = true;
  281. } else {
  282. ret = regulator_disable(mhcd->vbus);
  283. if (ret) {
  284. pr_err("unable to disable vbus\n");
  285. return;
  286. }
  287. mhcd->vbus_on = false;
  288. }
  289. }
  290. static irqreturn_t msm_ehci_dock_connect_irq(int irq, void *data)
  291. {
  292. const struct msm_usb_host_platform_data *pdata;
  293. struct msm_hcd *mhcd = data;
  294. struct usb_hcd *hcd = mhcd_to_hcd(mhcd);
  295. pdata = mhcd->dev->platform_data;
  296. if (atomic_read(&mhcd->in_lpm))
  297. usb_hcd_resume_root_hub(hcd);
  298. if (irq_read_line(pdata->dock_connect_irq)) {
  299. dev_dbg(mhcd->dev, "%s:Dock removed disable vbus\n", __func__);
  300. msm_ehci_vbus_power(mhcd, 0);
  301. } else {
  302. dev_dbg(mhcd->dev, "%s:Dock connected enable vbus\n", __func__);
  303. msm_ehci_vbus_power(mhcd, 1);
  304. }
  305. return IRQ_HANDLED;
  306. }
  307. static int msm_ehci_init_vbus(struct msm_hcd *mhcd, int init)
  308. {
  309. int rc = 0;
  310. struct usb_hcd *hcd = mhcd_to_hcd(mhcd);
  311. const struct msm_usb_host_platform_data *pdata;
  312. int ret = 0;
  313. pdata = mhcd->dev->platform_data;
  314. /* For uicc card connection, external vbus is not required */
  315. if (pdata && pdata->is_uicc)
  316. return 0;
  317. if (!init) {
  318. if (pdata && pdata->dock_connect_irq)
  319. free_irq(pdata->dock_connect_irq, mhcd);
  320. return rc;
  321. }
  322. mhcd->vbus = devm_regulator_get(mhcd->dev, "vbus");
  323. ret = PTR_ERR(mhcd->vbus);
  324. if (ret == -EPROBE_DEFER) {
  325. pr_debug("failed to get vbus handle, defer probe\n");
  326. return ret;
  327. } else if (IS_ERR(mhcd->vbus)) {
  328. pr_err("Unable to get vbus\n");
  329. return -ENODEV;
  330. }
  331. if (pdata) {
  332. hcd->power_budget = pdata->power_budget;
  333. if (pdata->dock_connect_irq) {
  334. rc = request_threaded_irq(pdata->dock_connect_irq, NULL,
  335. msm_ehci_dock_connect_irq,
  336. IRQF_TRIGGER_FALLING |
  337. IRQF_TRIGGER_RISING |
  338. IRQF_ONESHOT, "msm_ehci_host", mhcd);
  339. if (!rc)
  340. enable_irq_wake(pdata->dock_connect_irq);
  341. }
  342. }
  343. return rc;
  344. }
  345. static int msm_ehci_ldo_enable(struct msm_hcd *mhcd, int on)
  346. {
  347. int ret = 0;
  348. if (IS_ERR(mhcd->hsusb_1p8)) {
  349. dev_err(mhcd->dev, "%s: HSUSB_1p8 is not initialized\n",
  350. __func__);
  351. return -ENODEV;
  352. }
  353. if (IS_ERR(mhcd->hsusb_3p3)) {
  354. dev_err(mhcd->dev, "%s: HSUSB_3p3 is not initialized\n",
  355. __func__);
  356. return -ENODEV;
  357. }
  358. if (on) {
  359. ret = regulator_set_optimum_mode(mhcd->hsusb_1p8,
  360. HSUSB_PHY_1P8_HPM_LOAD);
  361. if (ret < 0) {
  362. dev_err(mhcd->dev, "%s: Unable to set HPM of the"
  363. " regulator: HSUSB_1p8\n", __func__);
  364. return ret;
  365. }
  366. ret = regulator_enable(mhcd->hsusb_1p8);
  367. if (ret) {
  368. dev_err(mhcd->dev, "%s: unable to enable the hsusb"
  369. " 1p8\n", __func__);
  370. regulator_set_optimum_mode(mhcd->hsusb_1p8, 0);
  371. return ret;
  372. }
  373. ret = regulator_set_optimum_mode(mhcd->hsusb_3p3,
  374. HSUSB_PHY_3P3_HPM_LOAD);
  375. if (ret < 0) {
  376. dev_err(mhcd->dev, "%s: Unable to set HPM of the "
  377. "regulator: HSUSB_3p3\n", __func__);
  378. regulator_set_optimum_mode(mhcd->hsusb_1p8, 0);
  379. regulator_disable(mhcd->hsusb_1p8);
  380. return ret;
  381. }
  382. ret = regulator_enable(mhcd->hsusb_3p3);
  383. if (ret) {
  384. dev_err(mhcd->dev, "%s: unable to enable the "
  385. "hsusb 3p3\n", __func__);
  386. regulator_set_optimum_mode(mhcd->hsusb_3p3, 0);
  387. regulator_set_optimum_mode(mhcd->hsusb_1p8, 0);
  388. regulator_disable(mhcd->hsusb_1p8);
  389. return ret;
  390. }
  391. } else {
  392. ret = regulator_disable(mhcd->hsusb_1p8);
  393. if (ret) {
  394. dev_err(mhcd->dev, "%s: unable to disable the "
  395. "hsusb 1p8\n", __func__);
  396. return ret;
  397. }
  398. ret = regulator_set_optimum_mode(mhcd->hsusb_1p8, 0);
  399. if (ret < 0)
  400. dev_err(mhcd->dev, "%s: Unable to set LPM of the "
  401. "regulator: HSUSB_1p8\n", __func__);
  402. ret = regulator_disable(mhcd->hsusb_3p3);
  403. if (ret) {
  404. dev_err(mhcd->dev, "%s: unable to disable the "
  405. "hsusb 3p3\n", __func__);
  406. return ret;
  407. }
  408. ret = regulator_set_optimum_mode(mhcd->hsusb_3p3, 0);
  409. if (ret < 0)
  410. dev_err(mhcd->dev, "%s: Unable to set LPM of the "
  411. "regulator: HSUSB_3p3\n", __func__);
  412. }
  413. dev_dbg(mhcd->dev, "reg (%s)\n", on ? "HPM" : "LPM");
  414. return ret < 0 ? ret : 0;
  415. }
  416. #define ULPI_IO_TIMEOUT_USECS (10 * 1000)
  417. static int msm_ulpi_read(struct msm_hcd *mhcd, u32 reg)
  418. {
  419. struct usb_hcd *hcd = mhcd_to_hcd(mhcd);
  420. unsigned long timeout;
  421. /* initiate read operation */
  422. writel_relaxed(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg),
  423. USB_ULPI_VIEWPORT);
  424. /* wait for completion */
  425. timeout = jiffies + usecs_to_jiffies(ULPI_IO_TIMEOUT_USECS);
  426. while (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN) {
  427. if (time_after(jiffies, timeout)) {
  428. dev_err(mhcd->dev, "msm_ulpi_read: timeout %08x\n",
  429. readl_relaxed(USB_ULPI_VIEWPORT));
  430. dev_err(mhcd->dev, "PORTSC: %08x USBCMD: %08x\n",
  431. readl_relaxed(USB_PORTSC),
  432. readl_relaxed(USB_USBCMD));
  433. return -ETIMEDOUT;
  434. }
  435. udelay(1);
  436. }
  437. return ULPI_DATA_READ(readl_relaxed(USB_ULPI_VIEWPORT));
  438. }
  439. static int msm_ulpi_write(struct msm_hcd *mhcd, u32 val, u32 reg)
  440. {
  441. struct usb_hcd *hcd = mhcd_to_hcd(mhcd);
  442. unsigned long timeout;
  443. /* initiate write operation */
  444. writel_relaxed(ULPI_RUN | ULPI_WRITE |
  445. ULPI_ADDR(reg) | ULPI_DATA(val),
  446. USB_ULPI_VIEWPORT);
  447. /* wait for completion */
  448. timeout = jiffies + usecs_to_jiffies(ULPI_IO_TIMEOUT_USECS);
  449. while (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN) {
  450. if (time_after(jiffies, timeout)) {
  451. dev_err(mhcd->dev, "msm_ulpi_write: timeout\n");
  452. dev_err(mhcd->dev, "PORTSC: %08x USBCMD: %08x\n",
  453. readl_relaxed(USB_PORTSC),
  454. readl_relaxed(USB_USBCMD));
  455. return -ETIMEDOUT;
  456. }
  457. udelay(1);
  458. }
  459. return 0;
  460. }
  461. /**
  462. * Do hard reset to USB hardware block using one of reset methodology based
  463. * on availablity of alt_core_clk. There are two kinds of hardware resets.
  464. * 1. Conventional synchronous reset where clocks to blocks to be ON while
  465. * issuing the reset. 2. Asynchronous reset which requires clocks to be OFF.
  466. */
  467. static int msm_ehci_link_clk_reset(struct msm_hcd *mhcd, bool assert)
  468. {
  469. int ret;
  470. if (assert) {
  471. if (!IS_ERR(mhcd->alt_core_clk)) {
  472. ret = clk_reset(mhcd->alt_core_clk, CLK_RESET_ASSERT);
  473. } else {
  474. /* Using asynchronous block reset to the hardware */
  475. clk_disable(mhcd->iface_clk);
  476. clk_disable(mhcd->core_clk);
  477. ret = clk_reset(mhcd->core_clk, CLK_RESET_ASSERT);
  478. }
  479. if (ret)
  480. dev_err(mhcd->dev, "usb clk assert failed\n");
  481. } else {
  482. if (!IS_ERR(mhcd->alt_core_clk)) {
  483. ret = clk_reset(mhcd->alt_core_clk, CLK_RESET_DEASSERT);
  484. } else {
  485. ret = clk_reset(mhcd->core_clk, CLK_RESET_DEASSERT);
  486. ndelay(200);
  487. clk_enable(mhcd->core_clk);
  488. clk_enable(mhcd->iface_clk);
  489. }
  490. if (ret)
  491. dev_err(mhcd->dev, "usb clk deassert failed\n");
  492. }
  493. return ret;
  494. }
  495. static int msm_ehci_phy_reset(struct msm_hcd *mhcd)
  496. {
  497. struct usb_hcd *hcd = mhcd_to_hcd(mhcd);
  498. struct msm_usb_host_platform_data *pdata;
  499. u32 val;
  500. int ret;
  501. ret = msm_ehci_link_clk_reset(mhcd, 1);
  502. if (ret)
  503. return ret;
  504. /* Minimum 10msec delay for block reset as per hardware spec */
  505. usleep_range(10000, 12000);
  506. ret = msm_ehci_link_clk_reset(mhcd, 0);
  507. if (ret)
  508. return ret;
  509. pdata = mhcd->dev->platform_data;
  510. if (pdata && pdata->use_sec_phy)
  511. /* select secondary phy if offset is set for USB operation */
  512. writel_relaxed(readl_relaxed(USB_PHY_CTRL2) | (1<<16),
  513. USB_PHY_CTRL2);
  514. val = readl_relaxed(USB_PORTSC) & ~PORTSC_PTS_MASK;
  515. writel_relaxed(val | PORTSC_PTS_ULPI, USB_PORTSC);
  516. dev_info(mhcd->dev, "phy_reset: success\n");
  517. return 0;
  518. }
  519. static void usb_phy_reset(struct msm_hcd *mhcd)
  520. {
  521. u32 val;
  522. /* Assert USB PHY_PON */
  523. val = readl_relaxed(mhcd->usb_phy_ctrl_reg);
  524. val &= ~PHY_POR_BIT_MASK;
  525. val |= PHY_POR_ASSERT;
  526. writel_relaxed(val, mhcd->usb_phy_ctrl_reg);
  527. /* wait for minimum 10 microseconds as suggested in hardware spec */
  528. usleep_range(10, 15);
  529. /* Deassert USB PHY_PON */
  530. val = readl_relaxed(mhcd->usb_phy_ctrl_reg);
  531. val &= ~PHY_POR_BIT_MASK;
  532. val |= PHY_POR_DEASSERT;
  533. writel_relaxed(val, mhcd->usb_phy_ctrl_reg);
  534. /* Ensure that RESET operation is completed. */
  535. mb();
  536. }
  537. #define LINK_RESET_TIMEOUT_USEC (250 * 1000)
  538. static int msm_hsusb_reset(struct msm_hcd *mhcd)
  539. {
  540. struct usb_hcd *hcd = mhcd_to_hcd(mhcd);
  541. struct msm_usb_host_platform_data *pdata;
  542. unsigned long timeout;
  543. int ret;
  544. if (!IS_ERR(mhcd->alt_core_clk))
  545. clk_prepare_enable(mhcd->alt_core_clk);
  546. ret = msm_ehci_phy_reset(mhcd);
  547. if (ret) {
  548. dev_err(mhcd->dev, "phy_reset failed\n");
  549. return ret;
  550. }
  551. writel_relaxed(USBCMD_RESET, USB_USBCMD);
  552. timeout = jiffies + usecs_to_jiffies(LINK_RESET_TIMEOUT_USEC);
  553. while (readl_relaxed(USB_USBCMD) & USBCMD_RESET) {
  554. if (time_after(jiffies, timeout))
  555. return -ETIMEDOUT;
  556. udelay(1);
  557. }
  558. /* select ULPI phy */
  559. writel_relaxed(0x80000000, USB_PORTSC);
  560. pdata = mhcd->dev->platform_data;
  561. if (pdata && pdata->use_sec_phy)
  562. writel_relaxed(readl_relaxed(USB_PHY_CTRL2) | (1<<16),
  563. USB_PHY_CTRL2);
  564. /* Reset USB PHY after performing USB Link RESET */
  565. usb_phy_reset(mhcd);
  566. msleep(100);
  567. writel_relaxed(0x0, USB_AHBBURST);
  568. writel_relaxed(0x08, USB_AHBMODE);
  569. /* Ensure that RESET operation is completed before turning off clock */
  570. mb();
  571. if (!IS_ERR(mhcd->alt_core_clk))
  572. clk_disable_unprepare(mhcd->alt_core_clk);
  573. /*rising edge interrupts with Dp rise and fall enabled*/
  574. msm_ulpi_write(mhcd, ULPI_INT_DP, ULPI_USB_INT_EN_RISE);
  575. msm_ulpi_write(mhcd, ULPI_INT_DP, ULPI_USB_INT_EN_FALL);
  576. /*Clear the PHY interrupts by reading the PHY interrupt latch register*/
  577. msm_ulpi_read(mhcd, ULPI_USB_INT_LATCH);
  578. return 0;
  579. }
  580. static void msm_ehci_phy_susp_fail_work(struct work_struct *w)
  581. {
  582. struct msm_hcd *mhcd = container_of(w, struct msm_hcd,
  583. phy_susp_fail_work);
  584. struct usb_hcd *hcd = mhcd_to_hcd(mhcd);
  585. msm_ehci_vbus_power(mhcd, 0);
  586. usb_remove_hcd(hcd);
  587. msm_hsusb_reset(mhcd);
  588. usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
  589. msm_ehci_vbus_power(mhcd, 1);
  590. }
  591. #define PHY_SUSP_TIMEOUT_MSEC 500
  592. #define PHY_RESUME_TIMEOUT_USEC (100 * 1000)
  593. #ifdef CONFIG_PM_SLEEP
  594. static int msm_ehci_suspend(struct msm_hcd *mhcd)
  595. {
  596. struct usb_hcd *hcd = mhcd_to_hcd(mhcd);
  597. unsigned long timeout;
  598. int ret;
  599. u32 portsc;
  600. const struct msm_usb_host_platform_data *pdata;
  601. u32 func_ctrl;
  602. if (atomic_read(&mhcd->in_lpm)) {
  603. dev_dbg(mhcd->dev, "%s called in lpm\n", __func__);
  604. return 0;
  605. }
  606. disable_irq(hcd->irq);
  607. /* make sure we don't race against a remote wakeup */
  608. if (test_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags) ||
  609. readl_relaxed(USB_PORTSC) & PORT_RESUME) {
  610. dev_dbg(mhcd->dev, "wakeup pending, aborting suspend\n");
  611. enable_irq(hcd->irq);
  612. return -EBUSY;
  613. }
  614. pdata = mhcd->dev->platform_data;
  615. if (pdata && pdata->is_uicc) {
  616. /* put the controller in non-driving mode */
  617. func_ctrl = msm_ulpi_read(mhcd, ULPI_FUNC_CTRL);
  618. func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
  619. func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
  620. msm_ulpi_write(mhcd, func_ctrl, ULPI_FUNC_CTRL);
  621. }
  622. /* If port is enabled wait 5ms for PHCD to come up. Reset PHY
  623. * and link if it fails to do so.
  624. * If port is not enabled set the PHCD bit and poll for it to
  625. * come up with in 500ms. Reset phy and link if it fails to do so.
  626. */
  627. portsc = readl_relaxed(USB_PORTSC);
  628. if (portsc & PORT_PE) {
  629. usleep_range(5000, 5000);
  630. if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) {
  631. dev_err(mhcd->dev,
  632. "Unable to suspend PHY. portsc: %8x\n",
  633. readl_relaxed(USB_PORTSC));
  634. goto reset_phy_and_link;
  635. }
  636. } else {
  637. writel_relaxed(portsc | PORTSC_PHCD, USB_PORTSC);
  638. timeout = jiffies + msecs_to_jiffies(PHY_SUSP_TIMEOUT_MSEC);
  639. while (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) {
  640. if (time_after(jiffies, timeout)) {
  641. dev_err(mhcd->dev,
  642. "Unable to suspend PHY. portsc: %8x\n",
  643. readl_relaxed(USB_PORTSC));
  644. goto reset_phy_and_link;
  645. }
  646. usleep_range(10000, 10000);
  647. }
  648. }
  649. /*
  650. * PHY has capability to generate interrupt asynchronously in low
  651. * power mode (LPM). This interrupt is level triggered. So USB IRQ
  652. * line must be disabled till async interrupt enable bit is cleared
  653. * in USBCMD register. Assert STP (ULPI interface STOP signal) to
  654. * block data communication from PHY. Enable asynchronous interrupt
  655. * only when wakeup gpio IRQ is not present.
  656. */
  657. if (mhcd->wakeup_irq)
  658. writel_relaxed(readl_relaxed(USB_USBCMD) | ULPI_STP_CTRL,
  659. USB_USBCMD);
  660. else
  661. writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL |
  662. ULPI_STP_CTRL, USB_USBCMD);
  663. /*
  664. * Ensure that hardware is put in low power mode before
  665. * clocks are turned OFF and VDD is allowed to minimize.
  666. */
  667. mb();
  668. clk_disable_unprepare(mhcd->iface_clk);
  669. clk_disable_unprepare(mhcd->core_clk);
  670. /* usb phy does not require TCXO clock, hence vote for TCXO disable */
  671. if (!IS_ERR(mhcd->xo_clk)) {
  672. clk_disable_unprepare(mhcd->xo_clk);
  673. } else {
  674. ret = msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_OFF);
  675. if (ret)
  676. dev_err(mhcd->dev, "%s failed to devote for TCXO %d\n",
  677. __func__, ret);
  678. }
  679. msm_ehci_config_vddcx(mhcd, 0);
  680. atomic_set(&mhcd->in_lpm, 1);
  681. enable_irq(hcd->irq);
  682. if (mhcd->wakeup_irq) {
  683. mhcd->wakeup_irq_enabled = 1;
  684. enable_irq_wake(mhcd->wakeup_irq);
  685. enable_irq(mhcd->wakeup_irq);
  686. }
  687. if (mhcd->pmic_gpio_dp_irq) {
  688. mhcd->pmic_gpio_dp_irq_enabled = 1;
  689. enable_irq_wake(mhcd->pmic_gpio_dp_irq);
  690. enable_irq(mhcd->pmic_gpio_dp_irq);
  691. }
  692. if (mhcd->async_irq) {
  693. mhcd->async_irq_enabled = 1;
  694. enable_irq_wake(mhcd->async_irq);
  695. enable_irq(mhcd->async_irq);
  696. }
  697. pm_relax(mhcd->dev);
  698. dev_info(mhcd->dev, "EHCI USB in low power mode\n");
  699. return 0;
  700. reset_phy_and_link:
  701. schedule_work(&mhcd->phy_susp_fail_work);
  702. return -ETIMEDOUT;
  703. }
  704. static int msm_ehci_resume(struct msm_hcd *mhcd)
  705. {
  706. struct usb_hcd *hcd = mhcd_to_hcd(mhcd);
  707. unsigned long timeout;
  708. unsigned temp;
  709. int ret;
  710. unsigned long flags;
  711. u32 func_ctrl;
  712. const struct msm_usb_host_platform_data *pdata;
  713. if (!atomic_read(&mhcd->in_lpm)) {
  714. dev_dbg(mhcd->dev, "%s called in !in_lpm\n", __func__);
  715. return 0;
  716. }
  717. if (mhcd->pmic_gpio_dp_irq_enabled) {
  718. disable_irq_wake(mhcd->pmic_gpio_dp_irq);
  719. disable_irq_nosync(mhcd->pmic_gpio_dp_irq);
  720. mhcd->pmic_gpio_dp_irq_enabled = 0;
  721. }
  722. spin_lock_irqsave(&mhcd->wakeup_lock, flags);
  723. if (mhcd->async_irq_enabled) {
  724. disable_irq_wake(mhcd->async_irq);
  725. disable_irq_nosync(mhcd->async_irq);
  726. mhcd->async_irq_enabled = 0;
  727. }
  728. if (mhcd->wakeup_irq) {
  729. if (mhcd->wakeup_irq_enabled) {
  730. disable_irq_wake(mhcd->wakeup_irq);
  731. disable_irq_nosync(mhcd->wakeup_irq);
  732. mhcd->wakeup_irq_enabled = 0;
  733. }
  734. }
  735. spin_unlock_irqrestore(&mhcd->wakeup_lock, flags);
  736. pm_stay_awake(mhcd->dev);
  737. /* Vote for TCXO when waking up the phy */
  738. if (!IS_ERR(mhcd->xo_clk)) {
  739. clk_prepare_enable(mhcd->xo_clk);
  740. } else {
  741. ret = msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_ON);
  742. if (ret)
  743. dev_err(mhcd->dev, "%s failed to vote for TCXO D0 %d\n",
  744. __func__, ret);
  745. }
  746. clk_prepare_enable(mhcd->core_clk);
  747. clk_prepare_enable(mhcd->iface_clk);
  748. msm_ehci_config_vddcx(mhcd, 1);
  749. temp = readl_relaxed(USB_USBCMD);
  750. temp &= ~ASYNC_INTR_CTRL;
  751. temp &= ~ULPI_STP_CTRL;
  752. writel_relaxed(temp, USB_USBCMD);
  753. if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD))
  754. goto skip_phy_resume;
  755. temp = readl_relaxed(USB_PORTSC) & ~PORTSC_PHCD;
  756. writel_relaxed(temp, USB_PORTSC);
  757. timeout = jiffies + usecs_to_jiffies(PHY_RESUME_TIMEOUT_USEC);
  758. while ((readl_relaxed(USB_PORTSC) & PORTSC_PHCD) ||
  759. !(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE)) {
  760. if (time_after(jiffies, timeout)) {
  761. /*This is a fatal error. Reset the link and PHY*/
  762. dev_err(mhcd->dev, "Unable to resume USB. Resetting the h/w\n");
  763. msm_hsusb_reset(mhcd);
  764. break;
  765. }
  766. udelay(1);
  767. }
  768. skip_phy_resume:
  769. pdata = mhcd->dev->platform_data;
  770. if (pdata && pdata->is_uicc) {
  771. /* put the controller in normal mode */
  772. func_ctrl = msm_ulpi_read(mhcd, ULPI_FUNC_CTRL);
  773. func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
  774. func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL;
  775. msm_ulpi_write(mhcd, func_ctrl, ULPI_FUNC_CTRL);
  776. }
  777. usb_hcd_resume_root_hub(hcd);
  778. atomic_set(&mhcd->in_lpm, 0);
  779. if (mhcd->async_int) {
  780. mhcd->async_int = false;
  781. pm_runtime_put_noidle(mhcd->dev);
  782. enable_irq(hcd->irq);
  783. }
  784. if (atomic_read(&mhcd->pm_usage_cnt)) {
  785. atomic_set(&mhcd->pm_usage_cnt, 0);
  786. pm_runtime_put_noidle(mhcd->dev);
  787. }
  788. dev_info(mhcd->dev, "EHCI USB exited from low power mode\n");
  789. return 0;
  790. }
  791. #endif
  792. static irqreturn_t msm_ehci_irq(struct usb_hcd *hcd)
  793. {
  794. struct msm_hcd *mhcd = hcd_to_mhcd(hcd);
  795. if (atomic_read(&mhcd->in_lpm)) {
  796. dev_dbg(mhcd->dev, "phy async intr\n");
  797. disable_irq_nosync(hcd->irq);
  798. mhcd->async_int = true;
  799. pm_runtime_get(mhcd->dev);
  800. return IRQ_HANDLED;
  801. }
  802. return ehci_irq(hcd);
  803. }
  804. static irqreturn_t msm_async_irq(int irq, void *data)
  805. {
  806. struct msm_hcd *mhcd = data;
  807. int ret;
  808. mhcd->async_int_cnt++;
  809. dev_dbg(mhcd->dev, "%s: hsusb host remote wakeup interrupt cnt: %u\n",
  810. __func__, mhcd->async_int_cnt);
  811. pm_stay_awake(mhcd->dev);
  812. spin_lock(&mhcd->wakeup_lock);
  813. if (mhcd->async_irq_enabled) {
  814. mhcd->async_irq_enabled = 0;
  815. disable_irq_wake(irq);
  816. disable_irq_nosync(irq);
  817. }
  818. spin_unlock(&mhcd->wakeup_lock);
  819. if (!atomic_read(&mhcd->pm_usage_cnt)) {
  820. ret = pm_runtime_get(mhcd->dev);
  821. if ((ret == 1) || (ret == -EINPROGRESS))
  822. pm_runtime_put_noidle(mhcd->dev);
  823. else
  824. atomic_set(&mhcd->pm_usage_cnt, 1);
  825. }
  826. return IRQ_HANDLED;
  827. }
  828. static irqreturn_t msm_ehci_host_wakeup_irq(int irq, void *data)
  829. {
  830. struct msm_hcd *mhcd = data;
  831. mhcd->pmic_gpio_int_cnt++;
  832. dev_dbg(mhcd->dev, "%s: hsusb host remote wakeup interrupt cnt: %u\n",
  833. __func__, mhcd->pmic_gpio_int_cnt);
  834. pm_stay_awake(mhcd->dev);
  835. if (mhcd->pmic_gpio_dp_irq_enabled) {
  836. mhcd->pmic_gpio_dp_irq_enabled = 0;
  837. disable_irq_wake(irq);
  838. disable_irq_nosync(irq);
  839. }
  840. if (!atomic_read(&mhcd->pm_usage_cnt)) {
  841. atomic_set(&mhcd->pm_usage_cnt, 1);
  842. pm_runtime_get(mhcd->dev);
  843. }
  844. return IRQ_HANDLED;
  845. }
  846. static int msm_ehci_reset(struct usb_hcd *hcd)
  847. {
  848. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  849. struct msm_hcd *mhcd = hcd_to_mhcd(hcd);
  850. struct msm_usb_host_platform_data *pdata;
  851. int retval;
  852. ehci->caps = USB_CAPLENGTH;
  853. ehci->regs = USB_CAPLENGTH +
  854. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  855. dbg_hcs_params(ehci, "reset");
  856. dbg_hcc_params(ehci, "reset");
  857. /* cache the data to minimize the chip reads*/
  858. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  859. hcd->has_tt = 1;
  860. ehci->sbrn = HCD_USB2;
  861. retval = ehci_halt(ehci);
  862. if (retval)
  863. return retval;
  864. /* data structure init */
  865. retval = ehci_init(hcd);
  866. if (retval)
  867. return retval;
  868. retval = ehci_reset(ehci);
  869. if (retval)
  870. return retval;
  871. /* bursts of unspecified length. */
  872. writel_relaxed(0, USB_AHBBURST);
  873. /* Use the AHB transactor */
  874. writel_relaxed(0x08, USB_AHBMODE);
  875. /* Disable streaming mode and select host mode */
  876. writel_relaxed(0x13, USB_USBMODE);
  877. pdata = mhcd->dev->platform_data;
  878. if (pdata && pdata->use_sec_phy)
  879. writel_relaxed(readl_relaxed(USB_PHY_CTRL2) | (1<<16),
  880. USB_PHY_CTRL2);
  881. ehci_port_power(ehci, 1);
  882. return 0;
  883. }
  884. static int msm_ehci_bus_resume_with_gpio(struct usb_hcd *hcd)
  885. {
  886. struct msm_hcd *mhcd = hcd_to_mhcd(hcd);
  887. int ret;
  888. gpio_direction_output(mhcd->resume_gpio, 1);
  889. ret = ehci_bus_resume(hcd);
  890. gpio_direction_output(mhcd->resume_gpio, 0);
  891. return ret;
  892. }
  893. #if defined(CONFIG_DEBUG_FS)
  894. static u32 addr;
  895. #define BUF_SIZE 32
  896. static ssize_t debug_read_phy_data(struct file *file, char __user *ubuf,
  897. size_t count, loff_t *ppos)
  898. {
  899. struct msm_hcd *mhcd = file->private_data;
  900. char *kbuf;
  901. size_t c = 0;
  902. u32 data = 0;
  903. int ret = 0;
  904. kbuf = kzalloc(sizeof(char) * BUF_SIZE, GFP_KERNEL);
  905. pm_runtime_get(mhcd->dev);
  906. data = msm_ulpi_read(mhcd, addr);
  907. pm_runtime_put(mhcd->dev);
  908. if (data < 0) {
  909. dev_err(mhcd->dev,
  910. "%s(): ulpi read timeout\n", __func__);
  911. return -ETIMEDOUT;
  912. }
  913. c = scnprintf(kbuf, BUF_SIZE, "addr: 0x%x: data: 0x%x\n", addr, data);
  914. ret = simple_read_from_buffer(ubuf, count, ppos, kbuf, c);
  915. kfree(kbuf);
  916. return ret;
  917. }
  918. static ssize_t debug_write_phy_data(struct file *file, const char __user *buf,
  919. size_t count, loff_t *ppos)
  920. {
  921. struct msm_hcd *mhcd = file->private_data;
  922. char kbuf[10];
  923. u32 data = 0;
  924. memset(kbuf, 0, 10);
  925. if (copy_from_user(kbuf, buf, min_t(size_t, sizeof(kbuf) - 1, count)))
  926. return -EFAULT;
  927. if (sscanf(kbuf, "%x", &data) != 1)
  928. return -EINVAL;
  929. pm_runtime_get(mhcd->dev);
  930. if (msm_ulpi_write(mhcd, data, addr) < 0) {
  931. dev_err(mhcd->dev,
  932. "%s(): ulpi write timeout\n", __func__);
  933. return -ETIMEDOUT;
  934. }
  935. pm_runtime_put(mhcd->dev);
  936. return count;
  937. }
  938. static ssize_t debug_phy_write_addr(struct file *file, const char __user *buf,
  939. size_t count, loff_t *ppos)
  940. {
  941. char kbuf[10];
  942. u32 temp;
  943. memset(kbuf, 0, 10);
  944. if (copy_from_user(kbuf, buf, min_t(size_t, sizeof(kbuf) - 1, count)))
  945. return -EFAULT;
  946. if (sscanf(kbuf, "%x", &temp) != 1)
  947. return -EINVAL;
  948. if (temp > 0x3F)
  949. return -EINVAL;
  950. addr = temp;
  951. return count;
  952. }
  953. static int debug_open(struct inode *inode, struct file *file)
  954. {
  955. file->private_data = inode->i_private;
  956. return 0;
  957. }
  958. const struct file_operations debug_rw_phy_ops = {
  959. .open = debug_open,
  960. .read = debug_read_phy_data,
  961. .write = debug_write_phy_data,
  962. };
  963. const struct file_operations debug_write_phy_ops = {
  964. .open = debug_open,
  965. .write = debug_phy_write_addr,
  966. };
  967. static struct dentry *dent_ehci;
  968. static int ehci_debugfs_init(struct msm_hcd *mhcd)
  969. {
  970. struct dentry *debug_phy_data;
  971. struct dentry *debug_phy_addr;
  972. dent_ehci = debugfs_create_dir(dev_name(mhcd->dev), 0);
  973. if (IS_ERR(dent_ehci))
  974. return -ENOENT;
  975. debug_phy_data = debugfs_create_file("phy_reg_data", 0666,
  976. dent_ehci, mhcd, &debug_rw_phy_ops);
  977. if (!debug_phy_data) {
  978. debugfs_remove(dent_ehci);
  979. return -ENOENT;
  980. }
  981. debug_phy_addr = debugfs_create_file("phy_reg_addr", 0666,
  982. dent_ehci, mhcd, &debug_write_phy_ops);
  983. if (!debug_phy_addr) {
  984. debugfs_remove_recursive(dent_ehci);
  985. return -ENOENT;
  986. }
  987. return 0;
  988. }
  989. #else
  990. static int ehci_debugfs_init(struct msm_hcd *mhcd)
  991. {
  992. return 0;
  993. }
  994. #endif
  995. static struct hc_driver msm_hc2_driver = {
  996. .description = hcd_name,
  997. .product_desc = "Qualcomm EHCI Host Controller",
  998. .hcd_priv_size = sizeof(struct msm_hcd),
  999. /*
  1000. * generic hardware linkage
  1001. */
  1002. .irq = msm_ehci_irq,
  1003. .flags = HCD_USB2 | HCD_MEMORY,
  1004. .reset = msm_ehci_reset,
  1005. .start = ehci_run,
  1006. .stop = ehci_stop,
  1007. .shutdown = ehci_shutdown,
  1008. /*
  1009. * managing i/o requests and associated device resources
  1010. */
  1011. .urb_enqueue = ehci_urb_enqueue,
  1012. .urb_dequeue = ehci_urb_dequeue,
  1013. .endpoint_disable = ehci_endpoint_disable,
  1014. .endpoint_reset = ehci_endpoint_reset,
  1015. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  1016. /*
  1017. * scheduling support
  1018. */
  1019. .get_frame_number = ehci_get_frame,
  1020. /*
  1021. * root hub support
  1022. */
  1023. .hub_status_data = ehci_hub_status_data,
  1024. .hub_control = ehci_hub_control,
  1025. .relinquish_port = ehci_relinquish_port,
  1026. .port_handed_over = ehci_port_handed_over,
  1027. /*
  1028. * PM support
  1029. */
  1030. .bus_suspend = ehci_bus_suspend,
  1031. .bus_resume = ehci_bus_resume,
  1032. };
  1033. static irqreturn_t msm_hsusb_wakeup_irq(int irq, void *data)
  1034. {
  1035. struct msm_hcd *mhcd = data;
  1036. int ret;
  1037. mhcd->wakeup_int_cnt++;
  1038. dev_dbg(mhcd->dev, "%s: hsic remote wakeup interrupt cnt: %u\n",
  1039. __func__, mhcd->wakeup_int_cnt);
  1040. pm_stay_awake(mhcd->dev);
  1041. spin_lock(&mhcd->wakeup_lock);
  1042. if (mhcd->wakeup_irq_enabled) {
  1043. mhcd->wakeup_irq_enabled = 0;
  1044. disable_irq_wake(irq);
  1045. disable_irq_nosync(irq);
  1046. }
  1047. spin_unlock(&mhcd->wakeup_lock);
  1048. if (!atomic_read(&mhcd->pm_usage_cnt)) {
  1049. ret = pm_runtime_get(mhcd->dev);
  1050. /*
  1051. * controller runtime resume can race with us.
  1052. * if we are active (ret == 1) or resuming
  1053. * (ret == -EINPROGRESS), decrement the
  1054. * PM usage counter before returning.
  1055. */
  1056. if ((ret == 1) || (ret == -EINPROGRESS)) {
  1057. pm_runtime_put_noidle(mhcd->dev);
  1058. } else {
  1059. /* Let khubd know of hub port status change */
  1060. if (mhcd->ehci.no_selective_suspend)
  1061. mhcd->ehci.suspended_ports = 1;
  1062. atomic_set(&mhcd->pm_usage_cnt, 1);
  1063. }
  1064. }
  1065. return IRQ_HANDLED;
  1066. }
  1067. static int msm_ehci_init_clocks(struct msm_hcd *mhcd, u32 init)
  1068. {
  1069. int ret = 0;
  1070. if (!init)
  1071. goto put_clocks;
  1072. /* 60MHz alt_core_clk is for LINK to be used during PHY RESET */
  1073. mhcd->alt_core_clk = clk_get(mhcd->dev, "alt_core_clk");
  1074. if (IS_ERR(mhcd->alt_core_clk))
  1075. dev_dbg(mhcd->dev, "failed to get alt_core_clk\n");
  1076. else
  1077. clk_set_rate(mhcd->alt_core_clk, 60000000);
  1078. /* iface_clk is required for data transfers */
  1079. mhcd->iface_clk = clk_get(mhcd->dev, "iface_clk");
  1080. if (IS_ERR(mhcd->iface_clk)) {
  1081. dev_err(mhcd->dev, "failed to get iface_clk\n");
  1082. ret = PTR_ERR(mhcd->iface_clk);
  1083. goto put_alt_core_clk;
  1084. }
  1085. /* Link's protocol engine is based on pclk which must
  1086. * be running >55Mhz and frequency should also not change.
  1087. * Hence, vote for maximum clk frequency on its source
  1088. */
  1089. mhcd->core_clk = clk_get(mhcd->dev, "core_clk");
  1090. if (IS_ERR(mhcd->core_clk)) {
  1091. dev_err(mhcd->dev, "failed to get core_clk\n");
  1092. ret = PTR_ERR(mhcd->core_clk);
  1093. goto put_iface_clk;
  1094. }
  1095. clk_set_rate(mhcd->core_clk, INT_MAX);
  1096. mhcd->phy_sleep_clk = clk_get(mhcd->dev, "sleep_clk");
  1097. if (IS_ERR(mhcd->phy_sleep_clk))
  1098. dev_dbg(mhcd->dev, "failed to get sleep_clk\n");
  1099. else
  1100. clk_prepare_enable(mhcd->phy_sleep_clk);
  1101. clk_prepare_enable(mhcd->core_clk);
  1102. clk_prepare_enable(mhcd->iface_clk);
  1103. return 0;
  1104. put_clocks:
  1105. if (!atomic_read(&mhcd->in_lpm)) {
  1106. clk_disable_unprepare(mhcd->iface_clk);
  1107. clk_disable_unprepare(mhcd->core_clk);
  1108. }
  1109. clk_put(mhcd->core_clk);
  1110. if (!IS_ERR(mhcd->phy_sleep_clk)) {
  1111. clk_disable_unprepare(mhcd->phy_sleep_clk);
  1112. clk_put(mhcd->phy_sleep_clk);
  1113. }
  1114. put_iface_clk:
  1115. clk_put(mhcd->iface_clk);
  1116. put_alt_core_clk:
  1117. if (!IS_ERR(mhcd->alt_core_clk))
  1118. clk_put(mhcd->alt_core_clk);
  1119. return ret;
  1120. }
  1121. struct msm_usb_host_platform_data *ehci_msm2_dt_to_pdata(
  1122. struct platform_device *pdev)
  1123. {
  1124. struct device_node *node = pdev->dev.of_node;
  1125. struct msm_usb_host_platform_data *pdata;
  1126. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  1127. if (!pdata) {
  1128. dev_err(&pdev->dev, "unable to allocate platform data\n");
  1129. return NULL;
  1130. }
  1131. pdata->use_sec_phy = of_property_read_bool(node,
  1132. "qcom,usb2-enable-hsphy2");
  1133. of_property_read_u32(node, "qcom,usb2-power-budget",
  1134. &pdata->power_budget);
  1135. pdata->no_selective_suspend = of_property_read_bool(node,
  1136. "qcom,no-selective-suspend");
  1137. pdata->resume_gpio = of_get_named_gpio(node, "qcom,resume-gpio", 0);
  1138. if (pdata->resume_gpio < 0)
  1139. pdata->resume_gpio = 0;
  1140. pdata->is_uicc = of_property_read_bool(node,
  1141. "qcom,usb2-enable-uicc");
  1142. return pdata;
  1143. }
  1144. static u64 ehci_msm_dma_mask = DMA_BIT_MASK(64);
  1145. static int __devinit ehci_msm2_probe(struct platform_device *pdev)
  1146. {
  1147. struct usb_hcd *hcd;
  1148. struct resource *res;
  1149. struct msm_hcd *mhcd;
  1150. const struct msm_usb_host_platform_data *pdata;
  1151. char pdev_name[PDEV_NAME_LEN];
  1152. int ret;
  1153. dev_dbg(&pdev->dev, "ehci_msm2 probe\n");
  1154. /*
  1155. * Fail probe in case of uicc till userspace activates driver through
  1156. * sysfs entry.
  1157. */
  1158. if (!uicc_card_present && pdev->dev.of_node && of_property_read_bool(
  1159. pdev->dev.of_node, "qcom,usb2-enable-uicc"))
  1160. return -ENODEV;
  1161. if (pdev->dev.of_node) {
  1162. dev_dbg(&pdev->dev, "device tree enabled\n");
  1163. pdev->dev.platform_data = ehci_msm2_dt_to_pdata(pdev);
  1164. }
  1165. if (!pdev->dev.platform_data)
  1166. dev_dbg(&pdev->dev, "No platform data given\n");
  1167. pdata = pdev->dev.platform_data;
  1168. if (!pdev->dev.dma_mask)
  1169. pdev->dev.dma_mask = &ehci_msm_dma_mask;
  1170. if (!pdev->dev.coherent_dma_mask)
  1171. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  1172. hcd = usb_create_hcd(&msm_hc2_driver, &pdev->dev,
  1173. dev_name(&pdev->dev));
  1174. if (!hcd) {
  1175. dev_err(&pdev->dev, "Unable to create HCD\n");
  1176. return -ENOMEM;
  1177. }
  1178. hcd_to_bus(hcd)->skip_resume = true;
  1179. hcd->irq = platform_get_irq(pdev, 0);
  1180. if (hcd->irq < 0) {
  1181. dev_err(&pdev->dev, "Unable to get IRQ resource\n");
  1182. ret = hcd->irq;
  1183. goto put_hcd;
  1184. }
  1185. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1186. if (!res) {
  1187. dev_err(&pdev->dev, "Unable to get memory resource\n");
  1188. ret = -ENODEV;
  1189. goto put_hcd;
  1190. }
  1191. hcd->rsrc_start = res->start;
  1192. hcd->rsrc_len = resource_size(res);
  1193. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  1194. if (!hcd->regs) {
  1195. dev_err(&pdev->dev, "ioremap failed\n");
  1196. ret = -ENOMEM;
  1197. goto put_hcd;
  1198. }
  1199. mhcd = hcd_to_mhcd(hcd);
  1200. mhcd->dev = &pdev->dev;
  1201. spin_lock_init(&mhcd->wakeup_lock);
  1202. mhcd->async_irq = platform_get_irq_byname(pdev, "async_irq");
  1203. if (mhcd->async_irq < 0) {
  1204. dev_dbg(&pdev->dev, "platform_get_irq for async_int failed\n");
  1205. mhcd->async_irq = 0;
  1206. } else {
  1207. ret = request_irq(mhcd->async_irq, msm_async_irq,
  1208. IRQF_TRIGGER_RISING, "msm_ehci_host", mhcd);
  1209. if (ret) {
  1210. dev_err(&pdev->dev, "request irq failed (ASYNC INT)\n");
  1211. goto unmap;
  1212. }
  1213. disable_irq(mhcd->async_irq);
  1214. }
  1215. snprintf(pdev_name, PDEV_NAME_LEN, "%s.%d", pdev->name, pdev->id);
  1216. mhcd->xo_clk = clk_get(&pdev->dev, "xo");
  1217. if (!IS_ERR(mhcd->xo_clk)) {
  1218. ret = clk_prepare_enable(mhcd->xo_clk);
  1219. } else {
  1220. mhcd->xo_handle = msm_xo_get(MSM_XO_TCXO_D0, pdev_name);
  1221. if (IS_ERR(mhcd->xo_handle)) {
  1222. dev_err(&pdev->dev, "%s fail to get handle for X0 D0\n",
  1223. __func__);
  1224. ret = PTR_ERR(mhcd->xo_handle);
  1225. goto free_async_irq;
  1226. } else {
  1227. ret = msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_ON);
  1228. }
  1229. }
  1230. if (ret) {
  1231. dev_err(&pdev->dev, "%s failed to vote for TCXO %d\n",
  1232. __func__, ret);
  1233. goto free_xo_handle;
  1234. }
  1235. if (pdata && pdata->resume_gpio) {
  1236. mhcd->resume_gpio = pdata->resume_gpio;
  1237. ret = gpio_request(mhcd->resume_gpio, "hsusb_resume");
  1238. if (ret) {
  1239. dev_err(&pdev->dev,
  1240. "resume gpio(%d) request failed:%d\n",
  1241. mhcd->resume_gpio, ret);
  1242. mhcd->resume_gpio = 0;
  1243. } else {
  1244. msm_hc2_driver.bus_resume =
  1245. msm_ehci_bus_resume_with_gpio;
  1246. }
  1247. }
  1248. spin_lock_init(&mhcd->wakeup_lock);
  1249. ret = msm_ehci_init_clocks(mhcd, 1);
  1250. if (ret) {
  1251. dev_err(&pdev->dev, "unable to initialize clocks\n");
  1252. ret = -ENODEV;
  1253. goto devote_xo_handle;
  1254. }
  1255. ret = msm_ehci_init_vddcx(mhcd, 1);
  1256. if (ret) {
  1257. dev_err(&pdev->dev, "unable to initialize VDDCX\n");
  1258. ret = -ENODEV;
  1259. goto deinit_clocks;
  1260. }
  1261. ret = msm_ehci_config_vddcx(mhcd, 1);
  1262. if (ret) {
  1263. dev_err(&pdev->dev, "hsusb vddcx configuration failed\n");
  1264. goto deinit_vddcx;
  1265. }
  1266. ret = msm_ehci_ldo_init(mhcd, 1);
  1267. if (ret) {
  1268. dev_err(&pdev->dev, "hsusb vreg configuration failed\n");
  1269. goto deinit_vddcx;
  1270. }
  1271. ret = msm_ehci_ldo_enable(mhcd, 1);
  1272. if (ret) {
  1273. dev_err(&pdev->dev, "hsusb vreg enable failed\n");
  1274. goto deinit_ldo;
  1275. }
  1276. ret = msm_ehci_init_vbus(mhcd, 1);
  1277. if (ret) {
  1278. dev_err(&pdev->dev, "unable to get vbus\n");
  1279. goto disable_ldo;
  1280. }
  1281. pdata = mhcd->dev->platform_data;
  1282. if (pdata && pdata->use_sec_phy)
  1283. mhcd->usb_phy_ctrl_reg = USB_PHY_CTRL2;
  1284. else
  1285. mhcd->usb_phy_ctrl_reg = USB_PHY_CTRL;
  1286. ret = msm_hsusb_reset(mhcd);
  1287. if (ret) {
  1288. dev_err(&pdev->dev, "hsusb PHY initialization failed\n");
  1289. goto vbus_deinit;
  1290. }
  1291. ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
  1292. if (ret) {
  1293. dev_err(&pdev->dev, "unable to register HCD\n");
  1294. goto vbus_deinit;
  1295. }
  1296. if (pdata && (!pdata->dock_connect_irq ||
  1297. !irq_read_line(pdata->dock_connect_irq)))
  1298. msm_ehci_vbus_power(mhcd, 1);
  1299. /* For peripherals directly conneted to downstream port of root hub
  1300. * and require to drive suspend and resume by controller driver instead
  1301. * of root hub.
  1302. */
  1303. if (pdata)
  1304. mhcd->ehci.no_selective_suspend = pdata->no_selective_suspend;
  1305. mhcd->wakeup_irq = platform_get_irq_byname(pdev, "wakeup_irq");
  1306. if (mhcd->wakeup_irq > 0) {
  1307. dev_dbg(&pdev->dev, "wakeup irq:%d\n", mhcd->wakeup_irq);
  1308. irq_set_status_flags(mhcd->wakeup_irq, IRQ_NOAUTOEN);
  1309. ret = request_irq(mhcd->wakeup_irq, msm_hsusb_wakeup_irq,
  1310. IRQF_TRIGGER_HIGH,
  1311. "msm_hsusb_wakeup", mhcd);
  1312. if (ret) {
  1313. dev_err(&pdev->dev, "request_irq(%d) failed:%d\n",
  1314. mhcd->wakeup_irq, ret);
  1315. mhcd->wakeup_irq = 0;
  1316. }
  1317. } else {
  1318. mhcd->wakeup_irq = 0;
  1319. }
  1320. device_init_wakeup(&pdev->dev, 1);
  1321. wakeup_source_init(&mhcd->ws, dev_name(&pdev->dev));
  1322. pm_stay_awake(mhcd->dev);
  1323. INIT_WORK(&mhcd->phy_susp_fail_work, msm_ehci_phy_susp_fail_work);
  1324. /*
  1325. * This pdev->dev is assigned parent of root-hub by USB core,
  1326. * hence, runtime framework automatically calls this driver's
  1327. * runtime APIs based on root-hub's state.
  1328. */
  1329. /* configure pmic_gpio_irq for D+ change */
  1330. if (pdata && pdata->pmic_gpio_dp_irq)
  1331. mhcd->pmic_gpio_dp_irq = pdata->pmic_gpio_dp_irq;
  1332. if (mhcd->pmic_gpio_dp_irq) {
  1333. ret = request_threaded_irq(mhcd->pmic_gpio_dp_irq, NULL,
  1334. msm_ehci_host_wakeup_irq,
  1335. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  1336. "msm_ehci_host_wakeup", mhcd);
  1337. if (!ret) {
  1338. disable_irq_nosync(mhcd->pmic_gpio_dp_irq);
  1339. } else {
  1340. dev_err(&pdev->dev, "request_irq(%d) failed: %d\n",
  1341. mhcd->pmic_gpio_dp_irq, ret);
  1342. mhcd->pmic_gpio_dp_irq = 0;
  1343. }
  1344. }
  1345. pm_runtime_set_active(&pdev->dev);
  1346. pm_runtime_enable(&pdev->dev);
  1347. if (ehci_debugfs_init(mhcd) < 0)
  1348. dev_err(mhcd->dev, "%s: debugfs init failed\n", __func__);
  1349. return 0;
  1350. vbus_deinit:
  1351. msm_ehci_init_vbus(mhcd, 0);
  1352. disable_ldo:
  1353. msm_ehci_ldo_enable(mhcd, 0);
  1354. deinit_ldo:
  1355. msm_ehci_ldo_init(mhcd, 0);
  1356. deinit_vddcx:
  1357. msm_ehci_init_vddcx(mhcd, 0);
  1358. deinit_clocks:
  1359. msm_ehci_init_clocks(mhcd, 0);
  1360. devote_xo_handle:
  1361. if (mhcd->resume_gpio)
  1362. gpio_free(mhcd->resume_gpio);
  1363. if (!IS_ERR(mhcd->xo_clk))
  1364. clk_disable_unprepare(mhcd->xo_clk);
  1365. else
  1366. msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_OFF);
  1367. free_xo_handle:
  1368. if (!IS_ERR(mhcd->xo_clk))
  1369. clk_put(mhcd->xo_clk);
  1370. else
  1371. msm_xo_put(mhcd->xo_handle);
  1372. free_async_irq:
  1373. if (mhcd->async_irq)
  1374. free_irq(mhcd->async_irq, mhcd);
  1375. unmap:
  1376. iounmap(hcd->regs);
  1377. put_hcd:
  1378. usb_put_hcd(hcd);
  1379. return ret;
  1380. }
  1381. static int __devexit ehci_msm2_remove(struct platform_device *pdev)
  1382. {
  1383. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  1384. struct msm_hcd *mhcd = hcd_to_mhcd(hcd);
  1385. if (mhcd->pmic_gpio_dp_irq) {
  1386. if (mhcd->pmic_gpio_dp_irq_enabled)
  1387. disable_irq_wake(mhcd->pmic_gpio_dp_irq);
  1388. free_irq(mhcd->pmic_gpio_dp_irq, mhcd);
  1389. }
  1390. if (mhcd->async_irq) {
  1391. if (mhcd->async_irq_enabled)
  1392. disable_irq_wake(mhcd->async_irq);
  1393. free_irq(mhcd->async_irq, mhcd);
  1394. }
  1395. if (mhcd->wakeup_irq) {
  1396. if (mhcd->wakeup_irq_enabled)
  1397. disable_irq_wake(mhcd->wakeup_irq);
  1398. free_irq(mhcd->wakeup_irq, mhcd);
  1399. }
  1400. if (mhcd->resume_gpio)
  1401. gpio_free(mhcd->resume_gpio);
  1402. /* If the device was removed no need to call pm_runtime_disable */
  1403. if (pdev->dev.power.power_state.event != PM_EVENT_INVALID)
  1404. pm_runtime_disable(&pdev->dev);
  1405. device_init_wakeup(&pdev->dev, 0);
  1406. pm_runtime_set_suspended(&pdev->dev);
  1407. usb_remove_hcd(hcd);
  1408. if (!IS_ERR(mhcd->xo_clk)) {
  1409. clk_disable_unprepare(mhcd->xo_clk);
  1410. clk_put(mhcd->xo_clk);
  1411. } else {
  1412. msm_xo_put(mhcd->xo_handle);
  1413. }
  1414. msm_ehci_vbus_power(mhcd, 0);
  1415. msm_ehci_init_vbus(mhcd, 0);
  1416. msm_ehci_ldo_enable(mhcd, 0);
  1417. msm_ehci_ldo_init(mhcd, 0);
  1418. msm_ehci_init_vddcx(mhcd, 0);
  1419. msm_ehci_init_clocks(mhcd, 0);
  1420. wakeup_source_trash(&mhcd->ws);
  1421. iounmap(hcd->regs);
  1422. usb_put_hcd(hcd);
  1423. #if defined(CONFIG_DEBUG_FS)
  1424. debugfs_remove_recursive(dent_ehci);
  1425. #endif
  1426. return 0;
  1427. }
  1428. #ifdef CONFIG_PM_SLEEP
  1429. static int ehci_msm2_pm_suspend(struct device *dev)
  1430. {
  1431. struct usb_hcd *hcd = dev_get_drvdata(dev);
  1432. struct msm_hcd *mhcd = hcd_to_mhcd(hcd);
  1433. dev_dbg(dev, "ehci-msm2 PM suspend\n");
  1434. if (device_may_wakeup(dev))
  1435. enable_irq_wake(hcd->irq);
  1436. return msm_ehci_suspend(mhcd);
  1437. }
  1438. static int ehci_msm2_pm_resume(struct device *dev)
  1439. {
  1440. int ret;
  1441. struct usb_hcd *hcd = dev_get_drvdata(dev);
  1442. struct msm_hcd *mhcd = hcd_to_mhcd(hcd);
  1443. dev_dbg(dev, "ehci-msm2 PM resume\n");
  1444. if (device_may_wakeup(dev))
  1445. disable_irq_wake(hcd->irq);
  1446. ret = msm_ehci_resume(mhcd);
  1447. if (ret)
  1448. return ret;
  1449. /* Bring the device to full powered state upon system resume */
  1450. pm_runtime_disable(dev);
  1451. pm_runtime_set_active(dev);
  1452. pm_runtime_enable(dev);
  1453. return 0;
  1454. }
  1455. #endif
  1456. #ifdef CONFIG_PM_RUNTIME
  1457. static int ehci_msm2_runtime_idle(struct device *dev)
  1458. {
  1459. dev_dbg(dev, "EHCI runtime idle\n");
  1460. return 0;
  1461. }
  1462. static int ehci_msm2_runtime_suspend(struct device *dev)
  1463. {
  1464. struct usb_hcd *hcd = dev_get_drvdata(dev);
  1465. struct msm_hcd *mhcd = hcd_to_mhcd(hcd);
  1466. dev_dbg(dev, "EHCI runtime suspend\n");
  1467. return msm_ehci_suspend(mhcd);
  1468. }
  1469. static int ehci_msm2_runtime_resume(struct device *dev)
  1470. {
  1471. struct usb_hcd *hcd = dev_get_drvdata(dev);
  1472. struct msm_hcd *mhcd = hcd_to_mhcd(hcd);
  1473. dev_dbg(dev, "EHCI runtime resume\n");
  1474. return msm_ehci_resume(mhcd);
  1475. }
  1476. #endif
  1477. #ifdef CONFIG_PM
  1478. static const struct dev_pm_ops ehci_msm2_dev_pm_ops = {
  1479. SET_SYSTEM_SLEEP_PM_OPS(ehci_msm2_pm_suspend, ehci_msm2_pm_resume)
  1480. SET_RUNTIME_PM_OPS(ehci_msm2_runtime_suspend, ehci_msm2_runtime_resume,
  1481. ehci_msm2_runtime_idle)
  1482. };
  1483. #endif
  1484. static const struct of_device_id ehci_msm2_dt_match[] = {
  1485. { .compatible = "qcom,ehci-host",
  1486. },
  1487. {}
  1488. };
  1489. static struct platform_driver ehci_msm2_driver = {
  1490. .probe = ehci_msm2_probe,
  1491. .remove = __devexit_p(ehci_msm2_remove),
  1492. .driver = {
  1493. .name = "msm_ehci_host",
  1494. #ifdef CONFIG_PM
  1495. .pm = &ehci_msm2_dev_pm_ops,
  1496. #endif
  1497. .of_match_table = ehci_msm2_dt_match,
  1498. },
  1499. };