phy-mapphone-mdm6600.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Motorola Mapphone MDM6600 modem GPIO controlled USB PHY driver
  4. * Copyright (C) 2018 Tony Lindgren <tony@atomide.com>
  5. */
  6. #include <linux/delay.h>
  7. #include <linux/err.h>
  8. #include <linux/io.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/slab.h>
  14. #include <linux/gpio/consumer.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/phy/phy.h>
  17. #define PHY_MDM6600_PHY_DELAY_MS 4000 /* PHY enable 2.2s to 3.5s */
  18. #define PHY_MDM6600_ENABLED_DELAY_MS 8000 /* 8s more total for MDM6600 */
  19. #define PHY_MDM6600_WAKE_KICK_MS 600 /* time on after GPIO toggle */
  20. #define MDM6600_MODEM_IDLE_DELAY_MS 1000 /* modem after USB suspend */
  21. #define MDM6600_MODEM_WAKE_DELAY_MS 200 /* modem response after idle */
  22. enum phy_mdm6600_ctrl_lines {
  23. PHY_MDM6600_ENABLE, /* USB PHY enable */
  24. PHY_MDM6600_POWER, /* Device power */
  25. PHY_MDM6600_RESET, /* Device reset */
  26. PHY_MDM6600_NR_CTRL_LINES,
  27. };
  28. enum phy_mdm6600_bootmode_lines {
  29. PHY_MDM6600_MODE0, /* out USB mode0 and OOB wake */
  30. PHY_MDM6600_MODE1, /* out USB mode1, in OOB wake */
  31. PHY_MDM6600_NR_MODE_LINES,
  32. };
  33. enum phy_mdm6600_cmd_lines {
  34. PHY_MDM6600_CMD0,
  35. PHY_MDM6600_CMD1,
  36. PHY_MDM6600_CMD2,
  37. PHY_MDM6600_NR_CMD_LINES,
  38. };
  39. enum phy_mdm6600_status_lines {
  40. PHY_MDM6600_STATUS0,
  41. PHY_MDM6600_STATUS1,
  42. PHY_MDM6600_STATUS2,
  43. PHY_MDM6600_NR_STATUS_LINES,
  44. };
  45. /*
  46. * MDM6600 command codes. These are based on Motorola Mapphone Linux
  47. * kernel tree.
  48. */
  49. enum phy_mdm6600_cmd {
  50. PHY_MDM6600_CMD_BP_PANIC_ACK,
  51. PHY_MDM6600_CMD_DATA_ONLY_BYPASS, /* Reroute USB to CPCAP PHY */
  52. PHY_MDM6600_CMD_FULL_BYPASS, /* Reroute USB to CPCAP PHY */
  53. PHY_MDM6600_CMD_NO_BYPASS, /* Request normal USB mode */
  54. PHY_MDM6600_CMD_BP_SHUTDOWN_REQ, /* Request device power off */
  55. PHY_MDM6600_CMD_BP_UNKNOWN_5,
  56. PHY_MDM6600_CMD_BP_UNKNOWN_6,
  57. PHY_MDM6600_CMD_UNDEFINED,
  58. };
  59. /*
  60. * MDM6600 status codes. These are based on Motorola Mapphone Linux
  61. * kernel tree.
  62. */
  63. enum phy_mdm6600_status {
  64. PHY_MDM6600_STATUS_PANIC, /* Seems to be really off */
  65. PHY_MDM6600_STATUS_PANIC_BUSY_WAIT,
  66. PHY_MDM6600_STATUS_QC_DLOAD,
  67. PHY_MDM6600_STATUS_RAM_DOWNLOADER, /* MDM6600 USB flashing mode */
  68. PHY_MDM6600_STATUS_PHONE_CODE_AWAKE, /* MDM6600 normal USB mode */
  69. PHY_MDM6600_STATUS_PHONE_CODE_ASLEEP,
  70. PHY_MDM6600_STATUS_SHUTDOWN_ACK,
  71. PHY_MDM6600_STATUS_UNDEFINED,
  72. };
  73. static const char * const
  74. phy_mdm6600_status_name[] = {
  75. "off", "busy", "qc_dl", "ram_dl", "awake",
  76. "asleep", "shutdown", "undefined",
  77. };
  78. struct phy_mdm6600 {
  79. struct device *dev;
  80. struct phy *generic_phy;
  81. struct phy_provider *phy_provider;
  82. struct gpio_desc *ctrl_gpios[PHY_MDM6600_NR_CTRL_LINES];
  83. struct gpio_descs *mode_gpios;
  84. struct gpio_descs *status_gpios;
  85. struct gpio_descs *cmd_gpios;
  86. struct delayed_work bootup_work;
  87. struct delayed_work status_work;
  88. struct delayed_work modem_wake_work;
  89. struct completion ack;
  90. bool enabled; /* mdm6600 phy enabled */
  91. bool running; /* mdm6600 boot done */
  92. bool awake; /* mdm6600 respnds on n_gsm */
  93. int status;
  94. };
  95. static int phy_mdm6600_init(struct phy *x)
  96. {
  97. struct phy_mdm6600 *ddata = phy_get_drvdata(x);
  98. struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE];
  99. if (!ddata->enabled)
  100. return -EPROBE_DEFER;
  101. gpiod_set_value_cansleep(enable_gpio, 0);
  102. return 0;
  103. }
  104. static int phy_mdm6600_power_on(struct phy *x)
  105. {
  106. struct phy_mdm6600 *ddata = phy_get_drvdata(x);
  107. struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE];
  108. if (!ddata->enabled)
  109. return -ENODEV;
  110. gpiod_set_value_cansleep(enable_gpio, 1);
  111. return 0;
  112. }
  113. static int phy_mdm6600_power_off(struct phy *x)
  114. {
  115. struct phy_mdm6600 *ddata = phy_get_drvdata(x);
  116. struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE];
  117. if (!ddata->enabled)
  118. return -ENODEV;
  119. gpiod_set_value_cansleep(enable_gpio, 0);
  120. return 0;
  121. }
  122. static const struct phy_ops gpio_usb_ops = {
  123. .init = phy_mdm6600_init,
  124. .power_on = phy_mdm6600_power_on,
  125. .power_off = phy_mdm6600_power_off,
  126. .owner = THIS_MODULE,
  127. };
  128. /**
  129. * phy_mdm6600_cmd() - send a command request to mdm6600
  130. * @ddata: device driver data
  131. *
  132. * Configures the three command request GPIOs to the specified value.
  133. */
  134. static void phy_mdm6600_cmd(struct phy_mdm6600 *ddata, int val)
  135. {
  136. int values[PHY_MDM6600_NR_CMD_LINES];
  137. int i;
  138. val &= (1 << PHY_MDM6600_NR_CMD_LINES) - 1;
  139. for (i = 0; i < PHY_MDM6600_NR_CMD_LINES; i++)
  140. values[i] = (val & BIT(i)) >> i;
  141. gpiod_set_array_value_cansleep(PHY_MDM6600_NR_CMD_LINES,
  142. ddata->cmd_gpios->desc, values);
  143. }
  144. /**
  145. * phy_mdm6600_status() - read mdm6600 status lines
  146. * @ddata: device driver data
  147. */
  148. static void phy_mdm6600_status(struct work_struct *work)
  149. {
  150. struct phy_mdm6600 *ddata;
  151. struct device *dev;
  152. int values[PHY_MDM6600_NR_STATUS_LINES];
  153. int error, i, val = 0;
  154. ddata = container_of(work, struct phy_mdm6600, status_work.work);
  155. dev = ddata->dev;
  156. error = gpiod_get_array_value_cansleep(PHY_MDM6600_NR_STATUS_LINES,
  157. ddata->status_gpios->desc,
  158. values);
  159. if (error)
  160. return;
  161. for (i = 0; i < PHY_MDM6600_NR_STATUS_LINES; i++) {
  162. val |= values[i] << i;
  163. dev_dbg(ddata->dev, "XXX %s: i: %i values[i]: %i val: %i\n",
  164. __func__, i, values[i], val);
  165. }
  166. ddata->status = val;
  167. dev_info(dev, "modem status: %i %s\n",
  168. ddata->status,
  169. phy_mdm6600_status_name[ddata->status & 7]);
  170. complete(&ddata->ack);
  171. }
  172. static irqreturn_t phy_mdm6600_irq_thread(int irq, void *data)
  173. {
  174. struct phy_mdm6600 *ddata = data;
  175. schedule_delayed_work(&ddata->status_work, msecs_to_jiffies(10));
  176. return IRQ_HANDLED;
  177. }
  178. /**
  179. * phy_mdm6600_wakeirq_thread - handle mode1 line OOB wake after booting
  180. * @irq: interrupt
  181. * @data: interrupt handler data
  182. *
  183. * GPIO mode1 is used initially as output to configure the USB boot
  184. * mode for mdm6600. After booting it is used as input for OOB wake
  185. * signal from mdm6600 to the SoC. Just use it for debug info only
  186. * for now.
  187. */
  188. static irqreturn_t phy_mdm6600_wakeirq_thread(int irq, void *data)
  189. {
  190. struct phy_mdm6600 *ddata = data;
  191. struct gpio_desc *mode_gpio1;
  192. int error, wakeup;
  193. mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1];
  194. wakeup = gpiod_get_value(mode_gpio1);
  195. if (!wakeup)
  196. return IRQ_NONE;
  197. dev_dbg(ddata->dev, "OOB wake on mode_gpio1: %i\n", wakeup);
  198. error = pm_runtime_get_sync(ddata->dev);
  199. if (error < 0) {
  200. pm_runtime_put_noidle(ddata->dev);
  201. return IRQ_NONE;
  202. }
  203. /* Just wake-up and kick the autosuspend timer */
  204. pm_runtime_mark_last_busy(ddata->dev);
  205. pm_runtime_put_autosuspend(ddata->dev);
  206. return IRQ_HANDLED;
  207. }
  208. /**
  209. * phy_mdm6600_init_irq() - initialize mdm6600 status IRQ lines
  210. * @ddata: device driver data
  211. */
  212. static void phy_mdm6600_init_irq(struct phy_mdm6600 *ddata)
  213. {
  214. struct device *dev = ddata->dev;
  215. int i, error, irq;
  216. for (i = PHY_MDM6600_STATUS0;
  217. i <= PHY_MDM6600_STATUS2; i++) {
  218. struct gpio_desc *gpio = ddata->status_gpios->desc[i];
  219. irq = gpiod_to_irq(gpio);
  220. if (irq <= 0)
  221. continue;
  222. error = devm_request_threaded_irq(dev, irq, NULL,
  223. phy_mdm6600_irq_thread,
  224. IRQF_TRIGGER_RISING |
  225. IRQF_TRIGGER_FALLING |
  226. IRQF_ONESHOT,
  227. "mdm6600",
  228. ddata);
  229. if (error)
  230. dev_warn(dev, "no modem status irq%i: %i\n",
  231. irq, error);
  232. }
  233. }
  234. struct phy_mdm6600_map {
  235. const char *name;
  236. int direction;
  237. };
  238. static const struct phy_mdm6600_map
  239. phy_mdm6600_ctrl_gpio_map[PHY_MDM6600_NR_CTRL_LINES] = {
  240. { "enable", GPIOD_OUT_LOW, }, /* low = phy disabled */
  241. { "power", GPIOD_OUT_LOW, }, /* low = off */
  242. { "reset", GPIOD_OUT_HIGH, }, /* high = reset */
  243. };
  244. /**
  245. * phy_mdm6600_init_lines() - initialize mdm6600 GPIO lines
  246. * @ddata: device driver data
  247. */
  248. static int phy_mdm6600_init_lines(struct phy_mdm6600 *ddata)
  249. {
  250. struct device *dev = ddata->dev;
  251. int i;
  252. /* MDM6600 control lines */
  253. for (i = 0; i < ARRAY_SIZE(phy_mdm6600_ctrl_gpio_map); i++) {
  254. const struct phy_mdm6600_map *map =
  255. &phy_mdm6600_ctrl_gpio_map[i];
  256. struct gpio_desc **gpio = &ddata->ctrl_gpios[i];
  257. *gpio = devm_gpiod_get(dev, map->name, map->direction);
  258. if (IS_ERR(*gpio)) {
  259. dev_info(dev, "gpio %s error %li\n",
  260. map->name, PTR_ERR(*gpio));
  261. return PTR_ERR(*gpio);
  262. }
  263. }
  264. /* MDM6600 USB start-up mode output lines */
  265. ddata->mode_gpios = devm_gpiod_get_array(dev, "motorola,mode",
  266. GPIOD_OUT_LOW);
  267. if (IS_ERR(ddata->mode_gpios))
  268. return PTR_ERR(ddata->mode_gpios);
  269. if (ddata->mode_gpios->ndescs != PHY_MDM6600_NR_MODE_LINES)
  270. return -EINVAL;
  271. /* MDM6600 status input lines */
  272. ddata->status_gpios = devm_gpiod_get_array(dev, "motorola,status",
  273. GPIOD_IN);
  274. if (IS_ERR(ddata->status_gpios))
  275. return PTR_ERR(ddata->status_gpios);
  276. if (ddata->status_gpios->ndescs != PHY_MDM6600_NR_STATUS_LINES)
  277. return -EINVAL;
  278. /* MDM6600 cmd output lines */
  279. ddata->cmd_gpios = devm_gpiod_get_array(dev, "motorola,cmd",
  280. GPIOD_OUT_LOW);
  281. if (IS_ERR(ddata->cmd_gpios))
  282. return PTR_ERR(ddata->cmd_gpios);
  283. if (ddata->cmd_gpios->ndescs != PHY_MDM6600_NR_CMD_LINES)
  284. return -EINVAL;
  285. return 0;
  286. }
  287. /**
  288. * phy_mdm6600_device_power_on() - power on mdm6600 device
  289. * @ddata: device driver data
  290. *
  291. * To get the integrated USB phy in MDM6600 takes some hoops. We must ensure
  292. * the shared USB bootmode GPIOs are configured, then request modem start-up,
  293. * reset and power-up.. And then we need to recycle the shared USB bootmode
  294. * GPIOs as they are also used for Out of Band (OOB) wake for the USB and
  295. * TS 27.010 serial mux.
  296. */
  297. static int phy_mdm6600_device_power_on(struct phy_mdm6600 *ddata)
  298. {
  299. struct gpio_desc *mode_gpio0, *mode_gpio1, *reset_gpio, *power_gpio;
  300. int error = 0, wakeirq;
  301. mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0];
  302. mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1];
  303. reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET];
  304. power_gpio = ddata->ctrl_gpios[PHY_MDM6600_POWER];
  305. /*
  306. * Shared GPIOs must be low for normal USB mode. After booting
  307. * they are used for OOB wake signaling. These can be also used
  308. * to configure USB flashing mode later on based on a module
  309. * parameter.
  310. */
  311. gpiod_set_value_cansleep(mode_gpio0, 0);
  312. gpiod_set_value_cansleep(mode_gpio1, 0);
  313. /* Request start-up mode */
  314. phy_mdm6600_cmd(ddata, PHY_MDM6600_CMD_NO_BYPASS);
  315. /* Request a reset first */
  316. gpiod_set_value_cansleep(reset_gpio, 0);
  317. msleep(100);
  318. /* Toggle power GPIO to request mdm6600 to start */
  319. gpiod_set_value_cansleep(power_gpio, 1);
  320. msleep(100);
  321. gpiod_set_value_cansleep(power_gpio, 0);
  322. /*
  323. * Looks like the USB PHY needs between 2.2 to 4 seconds.
  324. * If we try to use it before that, we will get L3 errors
  325. * from omap-usb-host trying to access the PHY. See also
  326. * phy_mdm6600_init() for -EPROBE_DEFER.
  327. */
  328. msleep(PHY_MDM6600_PHY_DELAY_MS);
  329. ddata->enabled = true;
  330. /* Booting up the rest of MDM6600 will take total about 8 seconds */
  331. dev_info(ddata->dev, "Waiting for power up request to complete..\n");
  332. if (wait_for_completion_timeout(&ddata->ack,
  333. msecs_to_jiffies(PHY_MDM6600_ENABLED_DELAY_MS))) {
  334. if (ddata->status > PHY_MDM6600_STATUS_PANIC &&
  335. ddata->status < PHY_MDM6600_STATUS_SHUTDOWN_ACK)
  336. dev_info(ddata->dev, "Powered up OK\n");
  337. } else {
  338. ddata->enabled = false;
  339. error = -ETIMEDOUT;
  340. dev_err(ddata->dev, "Timed out powering up\n");
  341. }
  342. /* Reconfigure mode1 GPIO as input for OOB wake */
  343. gpiod_direction_input(mode_gpio1);
  344. wakeirq = gpiod_to_irq(mode_gpio1);
  345. if (wakeirq <= 0)
  346. return wakeirq;
  347. error = devm_request_threaded_irq(ddata->dev, wakeirq, NULL,
  348. phy_mdm6600_wakeirq_thread,
  349. IRQF_TRIGGER_RISING |
  350. IRQF_TRIGGER_FALLING |
  351. IRQF_ONESHOT,
  352. "mdm6600-wake",
  353. ddata);
  354. if (error)
  355. dev_warn(ddata->dev, "no modem wakeirq irq%i: %i\n",
  356. wakeirq, error);
  357. ddata->running = true;
  358. return error;
  359. }
  360. /**
  361. * phy_mdm6600_device_power_off() - power off mdm6600 device
  362. * @ddata: device driver data
  363. */
  364. static void phy_mdm6600_device_power_off(struct phy_mdm6600 *ddata)
  365. {
  366. struct gpio_desc *reset_gpio =
  367. ddata->ctrl_gpios[PHY_MDM6600_RESET];
  368. ddata->enabled = false;
  369. phy_mdm6600_cmd(ddata, PHY_MDM6600_CMD_BP_SHUTDOWN_REQ);
  370. msleep(100);
  371. gpiod_set_value_cansleep(reset_gpio, 1);
  372. dev_info(ddata->dev, "Waiting for power down request to complete.. ");
  373. if (wait_for_completion_timeout(&ddata->ack,
  374. msecs_to_jiffies(5000))) {
  375. if (ddata->status == PHY_MDM6600_STATUS_PANIC)
  376. dev_info(ddata->dev, "Powered down OK\n");
  377. } else {
  378. dev_err(ddata->dev, "Timed out powering down\n");
  379. }
  380. }
  381. static void phy_mdm6600_deferred_power_on(struct work_struct *work)
  382. {
  383. struct phy_mdm6600 *ddata;
  384. int error;
  385. ddata = container_of(work, struct phy_mdm6600, bootup_work.work);
  386. error = phy_mdm6600_device_power_on(ddata);
  387. if (error)
  388. dev_err(ddata->dev, "Device not functional\n");
  389. }
  390. /*
  391. * USB suspend puts mdm6600 into low power mode. For any n_gsm using apps,
  392. * we need to keep the modem awake by kicking it's mode0 GPIO. This will
  393. * keep the modem awake for about 1.2 seconds. When no n_gsm apps are using
  394. * the modem, runtime PM auto mode can be enabled so modem can enter low
  395. * power mode.
  396. */
  397. static void phy_mdm6600_wake_modem(struct phy_mdm6600 *ddata)
  398. {
  399. struct gpio_desc *mode_gpio0;
  400. mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0];
  401. gpiod_set_value_cansleep(mode_gpio0, 1);
  402. usleep_range(5, 15);
  403. gpiod_set_value_cansleep(mode_gpio0, 0);
  404. if (ddata->awake)
  405. usleep_range(5, 15);
  406. else
  407. msleep(MDM6600_MODEM_WAKE_DELAY_MS);
  408. }
  409. static void phy_mdm6600_modem_wake(struct work_struct *work)
  410. {
  411. struct phy_mdm6600 *ddata;
  412. ddata = container_of(work, struct phy_mdm6600, modem_wake_work.work);
  413. phy_mdm6600_wake_modem(ddata);
  414. /*
  415. * The modem does not always stay awake 1.2 seconds after toggling
  416. * the wake GPIO, and sometimes it idles after about some 600 ms
  417. * making writes time out.
  418. */
  419. schedule_delayed_work(&ddata->modem_wake_work,
  420. msecs_to_jiffies(PHY_MDM6600_WAKE_KICK_MS));
  421. }
  422. static int __maybe_unused phy_mdm6600_runtime_suspend(struct device *dev)
  423. {
  424. struct phy_mdm6600 *ddata = dev_get_drvdata(dev);
  425. cancel_delayed_work_sync(&ddata->modem_wake_work);
  426. ddata->awake = false;
  427. return 0;
  428. }
  429. static int __maybe_unused phy_mdm6600_runtime_resume(struct device *dev)
  430. {
  431. struct phy_mdm6600 *ddata = dev_get_drvdata(dev);
  432. phy_mdm6600_modem_wake(&ddata->modem_wake_work.work);
  433. ddata->awake = true;
  434. return 0;
  435. }
  436. static const struct dev_pm_ops phy_mdm6600_pm_ops = {
  437. SET_RUNTIME_PM_OPS(phy_mdm6600_runtime_suspend,
  438. phy_mdm6600_runtime_resume, NULL)
  439. };
  440. static const struct of_device_id phy_mdm6600_id_table[] = {
  441. { .compatible = "motorola,mapphone-mdm6600", },
  442. {},
  443. };
  444. MODULE_DEVICE_TABLE(of, phy_mdm6600_id_table);
  445. static int phy_mdm6600_probe(struct platform_device *pdev)
  446. {
  447. struct phy_mdm6600 *ddata;
  448. int error;
  449. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  450. if (!ddata)
  451. return -ENOMEM;
  452. INIT_DELAYED_WORK(&ddata->bootup_work,
  453. phy_mdm6600_deferred_power_on);
  454. INIT_DELAYED_WORK(&ddata->status_work, phy_mdm6600_status);
  455. INIT_DELAYED_WORK(&ddata->modem_wake_work, phy_mdm6600_modem_wake);
  456. init_completion(&ddata->ack);
  457. ddata->dev = &pdev->dev;
  458. platform_set_drvdata(pdev, ddata);
  459. error = phy_mdm6600_init_lines(ddata);
  460. if (error)
  461. return error;
  462. phy_mdm6600_init_irq(ddata);
  463. ddata->generic_phy = devm_phy_create(ddata->dev, NULL, &gpio_usb_ops);
  464. if (IS_ERR(ddata->generic_phy)) {
  465. error = PTR_ERR(ddata->generic_phy);
  466. goto cleanup;
  467. }
  468. phy_set_drvdata(ddata->generic_phy, ddata);
  469. ddata->phy_provider =
  470. devm_of_phy_provider_register(ddata->dev,
  471. of_phy_simple_xlate);
  472. if (IS_ERR(ddata->phy_provider)) {
  473. error = PTR_ERR(ddata->phy_provider);
  474. goto cleanup;
  475. }
  476. schedule_delayed_work(&ddata->bootup_work, 0);
  477. /*
  478. * See phy_mdm6600_device_power_on(). We should be able
  479. * to remove this eventually when ohci-platform can deal
  480. * with -EPROBE_DEFER.
  481. */
  482. msleep(PHY_MDM6600_PHY_DELAY_MS + 500);
  483. /*
  484. * Enable PM runtime only after PHY has been powered up properly.
  485. * It is currently only needed after USB suspends mdm6600 and n_gsm
  486. * needs to access the device. We don't want to do this earlier as
  487. * gpio mode0 pin doubles as mdm6600 wake-up gpio.
  488. */
  489. pm_runtime_use_autosuspend(ddata->dev);
  490. pm_runtime_set_autosuspend_delay(ddata->dev,
  491. MDM6600_MODEM_IDLE_DELAY_MS);
  492. pm_runtime_enable(ddata->dev);
  493. error = pm_runtime_get_sync(ddata->dev);
  494. if (error < 0) {
  495. dev_warn(ddata->dev, "failed to wake modem: %i\n", error);
  496. pm_runtime_put_noidle(ddata->dev);
  497. }
  498. pm_runtime_mark_last_busy(ddata->dev);
  499. pm_runtime_put_autosuspend(ddata->dev);
  500. return 0;
  501. cleanup:
  502. phy_mdm6600_device_power_off(ddata);
  503. return error;
  504. }
  505. static int phy_mdm6600_remove(struct platform_device *pdev)
  506. {
  507. struct phy_mdm6600 *ddata = platform_get_drvdata(pdev);
  508. struct gpio_desc *reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET];
  509. pm_runtime_dont_use_autosuspend(ddata->dev);
  510. pm_runtime_put_sync(ddata->dev);
  511. pm_runtime_disable(ddata->dev);
  512. if (!ddata->running)
  513. wait_for_completion_timeout(&ddata->ack,
  514. msecs_to_jiffies(PHY_MDM6600_ENABLED_DELAY_MS));
  515. gpiod_set_value_cansleep(reset_gpio, 1);
  516. phy_mdm6600_device_power_off(ddata);
  517. cancel_delayed_work_sync(&ddata->modem_wake_work);
  518. cancel_delayed_work_sync(&ddata->bootup_work);
  519. cancel_delayed_work_sync(&ddata->status_work);
  520. return 0;
  521. }
  522. static struct platform_driver phy_mdm6600_driver = {
  523. .probe = phy_mdm6600_probe,
  524. .remove = phy_mdm6600_remove,
  525. .driver = {
  526. .name = "phy-mapphone-mdm6600",
  527. .pm = &phy_mdm6600_pm_ops,
  528. .of_match_table = of_match_ptr(phy_mdm6600_id_table),
  529. },
  530. };
  531. module_platform_driver(phy_mdm6600_driver);
  532. MODULE_ALIAS("platform:gpio_usb");
  533. MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>");
  534. MODULE_DESCRIPTION("mdm6600 gpio usb phy driver");
  535. MODULE_LICENSE("GPL v2");