common.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /*
  2. * Renesas USB driver
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. *
  16. */
  17. #include <linux/err.h>
  18. #include <linux/gpio.h>
  19. #include <linux/io.h>
  20. #include <linux/module.h>
  21. #include <linux/of_device.h>
  22. #include <linux/of_gpio.h>
  23. #include <linux/pm_runtime.h>
  24. #include <linux/slab.h>
  25. #include <linux/sysfs.h>
  26. #include "common.h"
  27. #include "rcar2.h"
  28. /*
  29. * image of renesas_usbhs
  30. *
  31. * ex) gadget case
  32. * mod.c
  33. * mod_gadget.c
  34. * mod_host.c pipe.c fifo.c
  35. *
  36. * +-------+ +-----------+
  37. * | pipe0 |------>| fifo pio |
  38. * +------------+ +-------+ +-----------+
  39. * | mod_gadget |=====> | pipe1 |--+
  40. * +------------+ +-------+ | +-----------+
  41. * | pipe2 | | +-| fifo dma0 |
  42. * +------------+ +-------+ | | +-----------+
  43. * | mod_host | | pipe3 |<-|--+
  44. * +------------+ +-------+ | +-----------+
  45. * | .... | +--->| fifo dma1 |
  46. * | .... | +-----------+
  47. */
  48. #define USBHSF_RUNTIME_PWCTRL (1 << 0)
  49. /* status */
  50. #define usbhsc_flags_init(p) do {(p)->flags = 0; } while (0)
  51. #define usbhsc_flags_set(p, b) ((p)->flags |= (b))
  52. #define usbhsc_flags_clr(p, b) ((p)->flags &= ~(b))
  53. #define usbhsc_flags_has(p, b) ((p)->flags & (b))
  54. /*
  55. * platform call back
  56. *
  57. * renesas usb support platform callback function.
  58. * Below macro call it.
  59. * if platform doesn't have callback, it return 0 (no error)
  60. */
  61. #define usbhs_platform_call(priv, func, args...)\
  62. (!(priv) ? -ENODEV : \
  63. !((priv)->pfunc.func) ? 0 : \
  64. (priv)->pfunc.func(args))
  65. /*
  66. * common functions
  67. */
  68. u16 usbhs_read(struct usbhs_priv *priv, u32 reg)
  69. {
  70. return ioread16(priv->base + reg);
  71. }
  72. void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data)
  73. {
  74. iowrite16(data, priv->base + reg);
  75. }
  76. void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data)
  77. {
  78. u16 val = usbhs_read(priv, reg);
  79. val &= ~mask;
  80. val |= data & mask;
  81. usbhs_write(priv, reg, val);
  82. }
  83. struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev)
  84. {
  85. return dev_get_drvdata(&pdev->dev);
  86. }
  87. /*
  88. * syscfg functions
  89. */
  90. static void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable)
  91. {
  92. usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0);
  93. }
  94. void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
  95. {
  96. u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
  97. u16 val = DCFM | DRPD | HSE | USBE;
  98. int has_otg = usbhs_get_dparam(priv, has_otg);
  99. if (has_otg)
  100. usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN));
  101. /*
  102. * if enable
  103. *
  104. * - select Host mode
  105. * - D+ Line/D- Line Pull-down
  106. */
  107. usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
  108. }
  109. void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
  110. {
  111. u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
  112. u16 val = HSE | USBE;
  113. /*
  114. * if enable
  115. *
  116. * - select Function mode
  117. * - D+ Line Pull-up is disabled
  118. * When D+ Line Pull-up is enabled,
  119. * calling usbhs_sys_function_pullup(,1)
  120. */
  121. usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
  122. }
  123. void usbhs_sys_function_pullup(struct usbhs_priv *priv, int enable)
  124. {
  125. usbhs_bset(priv, SYSCFG, DPRPU, enable ? DPRPU : 0);
  126. }
  127. void usbhs_sys_set_test_mode(struct usbhs_priv *priv, u16 mode)
  128. {
  129. usbhs_write(priv, TESTMODE, mode);
  130. }
  131. /*
  132. * frame functions
  133. */
  134. int usbhs_frame_get_num(struct usbhs_priv *priv)
  135. {
  136. return usbhs_read(priv, FRMNUM) & FRNM_MASK;
  137. }
  138. /*
  139. * usb request functions
  140. */
  141. void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
  142. {
  143. u16 val;
  144. val = usbhs_read(priv, USBREQ);
  145. req->bRequest = (val >> 8) & 0xFF;
  146. req->bRequestType = (val >> 0) & 0xFF;
  147. req->wValue = usbhs_read(priv, USBVAL);
  148. req->wIndex = usbhs_read(priv, USBINDX);
  149. req->wLength = usbhs_read(priv, USBLENG);
  150. }
  151. void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
  152. {
  153. usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType);
  154. usbhs_write(priv, USBVAL, req->wValue);
  155. usbhs_write(priv, USBINDX, req->wIndex);
  156. usbhs_write(priv, USBLENG, req->wLength);
  157. usbhs_bset(priv, DCPCTR, SUREQ, SUREQ);
  158. }
  159. /*
  160. * bus/vbus functions
  161. */
  162. void usbhs_bus_send_sof_enable(struct usbhs_priv *priv)
  163. {
  164. u16 status = usbhs_read(priv, DVSTCTR) & (USBRST | UACT);
  165. if (status != USBRST) {
  166. struct device *dev = usbhs_priv_to_dev(priv);
  167. dev_err(dev, "usbhs should be reset\n");
  168. }
  169. usbhs_bset(priv, DVSTCTR, (USBRST | UACT), UACT);
  170. }
  171. void usbhs_bus_send_reset(struct usbhs_priv *priv)
  172. {
  173. usbhs_bset(priv, DVSTCTR, (USBRST | UACT), USBRST);
  174. }
  175. int usbhs_bus_get_speed(struct usbhs_priv *priv)
  176. {
  177. u16 dvstctr = usbhs_read(priv, DVSTCTR);
  178. switch (RHST & dvstctr) {
  179. case RHST_LOW_SPEED:
  180. return USB_SPEED_LOW;
  181. case RHST_FULL_SPEED:
  182. return USB_SPEED_FULL;
  183. case RHST_HIGH_SPEED:
  184. return USB_SPEED_HIGH;
  185. }
  186. return USB_SPEED_UNKNOWN;
  187. }
  188. int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable)
  189. {
  190. struct platform_device *pdev = usbhs_priv_to_pdev(priv);
  191. return usbhs_platform_call(priv, set_vbus, pdev, enable);
  192. }
  193. static void usbhsc_bus_init(struct usbhs_priv *priv)
  194. {
  195. usbhs_write(priv, DVSTCTR, 0);
  196. usbhs_vbus_ctrl(priv, 0);
  197. }
  198. /*
  199. * device configuration
  200. */
  201. int usbhs_set_device_config(struct usbhs_priv *priv, int devnum,
  202. u16 upphub, u16 hubport, u16 speed)
  203. {
  204. struct device *dev = usbhs_priv_to_dev(priv);
  205. u16 usbspd = 0;
  206. u32 reg = DEVADD0 + (2 * devnum);
  207. if (devnum > 10) {
  208. dev_err(dev, "cannot set speed to unknown device %d\n", devnum);
  209. return -EIO;
  210. }
  211. if (upphub > 0xA) {
  212. dev_err(dev, "unsupported hub number %d\n", upphub);
  213. return -EIO;
  214. }
  215. switch (speed) {
  216. case USB_SPEED_LOW:
  217. usbspd = USBSPD_SPEED_LOW;
  218. break;
  219. case USB_SPEED_FULL:
  220. usbspd = USBSPD_SPEED_FULL;
  221. break;
  222. case USB_SPEED_HIGH:
  223. usbspd = USBSPD_SPEED_HIGH;
  224. break;
  225. default:
  226. dev_err(dev, "unsupported speed %d\n", speed);
  227. return -EIO;
  228. }
  229. usbhs_write(priv, reg, UPPHUB(upphub) |
  230. HUBPORT(hubport)|
  231. USBSPD(usbspd));
  232. return 0;
  233. }
  234. /*
  235. * local functions
  236. */
  237. static void usbhsc_set_buswait(struct usbhs_priv *priv)
  238. {
  239. int wait = usbhs_get_dparam(priv, buswait_bwait);
  240. /* set bus wait if platform have */
  241. if (wait)
  242. usbhs_bset(priv, BUSWAIT, 0x000F, wait);
  243. }
  244. /*
  245. * platform default param
  246. */
  247. /* commonly used on old SH-Mobile SoCs */
  248. static u32 usbhsc_default_pipe_type[] = {
  249. USB_ENDPOINT_XFER_CONTROL,
  250. USB_ENDPOINT_XFER_ISOC,
  251. USB_ENDPOINT_XFER_ISOC,
  252. USB_ENDPOINT_XFER_BULK,
  253. USB_ENDPOINT_XFER_BULK,
  254. USB_ENDPOINT_XFER_BULK,
  255. USB_ENDPOINT_XFER_INT,
  256. USB_ENDPOINT_XFER_INT,
  257. USB_ENDPOINT_XFER_INT,
  258. USB_ENDPOINT_XFER_INT,
  259. };
  260. /* commonly used on newer SH-Mobile and R-Car SoCs */
  261. static u32 usbhsc_new_pipe_type[] = {
  262. USB_ENDPOINT_XFER_CONTROL,
  263. USB_ENDPOINT_XFER_ISOC,
  264. USB_ENDPOINT_XFER_ISOC,
  265. USB_ENDPOINT_XFER_BULK,
  266. USB_ENDPOINT_XFER_BULK,
  267. USB_ENDPOINT_XFER_BULK,
  268. USB_ENDPOINT_XFER_INT,
  269. USB_ENDPOINT_XFER_INT,
  270. USB_ENDPOINT_XFER_INT,
  271. USB_ENDPOINT_XFER_BULK,
  272. USB_ENDPOINT_XFER_BULK,
  273. USB_ENDPOINT_XFER_BULK,
  274. USB_ENDPOINT_XFER_BULK,
  275. USB_ENDPOINT_XFER_BULK,
  276. USB_ENDPOINT_XFER_BULK,
  277. USB_ENDPOINT_XFER_BULK,
  278. };
  279. /*
  280. * power control
  281. */
  282. static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable)
  283. {
  284. struct platform_device *pdev = usbhs_priv_to_pdev(priv);
  285. struct device *dev = usbhs_priv_to_dev(priv);
  286. if (enable) {
  287. /* enable PM */
  288. pm_runtime_get_sync(dev);
  289. /* enable platform power */
  290. usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
  291. /* USB on */
  292. usbhs_sys_clock_ctrl(priv, enable);
  293. } else {
  294. /* USB off */
  295. usbhs_sys_clock_ctrl(priv, enable);
  296. /* disable platform power */
  297. usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
  298. /* disable PM */
  299. pm_runtime_put_sync(dev);
  300. }
  301. }
  302. /*
  303. * hotplug
  304. */
  305. static void usbhsc_hotplug(struct usbhs_priv *priv)
  306. {
  307. struct platform_device *pdev = usbhs_priv_to_pdev(priv);
  308. struct usbhs_mod *mod = usbhs_mod_get_current(priv);
  309. int id;
  310. int enable;
  311. int cable;
  312. int ret;
  313. /*
  314. * get vbus status from platform
  315. */
  316. enable = usbhs_platform_call(priv, get_vbus, pdev);
  317. /*
  318. * get id from platform
  319. */
  320. id = usbhs_platform_call(priv, get_id, pdev);
  321. if (enable && !mod) {
  322. if (priv->edev) {
  323. cable = extcon_get_cable_state(priv->edev, "USB-HOST");
  324. if ((cable > 0 && id != USBHS_HOST) ||
  325. (!cable && id != USBHS_GADGET)) {
  326. dev_info(&pdev->dev,
  327. "USB cable plugged in doesn't match the selected role!\n");
  328. return;
  329. }
  330. }
  331. ret = usbhs_mod_change(priv, id);
  332. if (ret < 0)
  333. return;
  334. dev_dbg(&pdev->dev, "%s enable\n", __func__);
  335. /* power on */
  336. if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
  337. usbhsc_power_ctrl(priv, enable);
  338. /* bus init */
  339. usbhsc_set_buswait(priv);
  340. usbhsc_bus_init(priv);
  341. /* module start */
  342. usbhs_mod_call(priv, start, priv);
  343. } else if (!enable && mod) {
  344. dev_dbg(&pdev->dev, "%s disable\n", __func__);
  345. /* module stop */
  346. usbhs_mod_call(priv, stop, priv);
  347. /* bus init */
  348. usbhsc_bus_init(priv);
  349. /* power off */
  350. if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
  351. usbhsc_power_ctrl(priv, enable);
  352. usbhs_mod_change(priv, -1);
  353. /* reset phy for next connection */
  354. usbhs_platform_call(priv, phy_reset, pdev);
  355. }
  356. }
  357. /*
  358. * notify hotplug
  359. */
  360. static void usbhsc_notify_hotplug(struct work_struct *work)
  361. {
  362. struct usbhs_priv *priv = container_of(work,
  363. struct usbhs_priv,
  364. notify_hotplug_work.work);
  365. usbhsc_hotplug(priv);
  366. }
  367. static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
  368. {
  369. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  370. int delay = usbhs_get_dparam(priv, detection_delay);
  371. /*
  372. * This functions will be called in interrupt.
  373. * To make sure safety context,
  374. * use workqueue for usbhs_notify_hotplug
  375. */
  376. schedule_delayed_work(&priv->notify_hotplug_work,
  377. msecs_to_jiffies(delay));
  378. return 0;
  379. }
  380. /*
  381. * platform functions
  382. */
  383. static const struct of_device_id usbhs_of_match[] = {
  384. {
  385. .compatible = "renesas,usbhs-r8a7790",
  386. .data = (void *)USBHS_TYPE_R8A7790,
  387. },
  388. {
  389. .compatible = "renesas,usbhs-r8a7791",
  390. .data = (void *)USBHS_TYPE_R8A7791,
  391. },
  392. { },
  393. };
  394. MODULE_DEVICE_TABLE(of, usbhs_of_match);
  395. static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev)
  396. {
  397. struct renesas_usbhs_platform_info *info;
  398. struct renesas_usbhs_driver_param *dparam;
  399. const struct of_device_id *of_id = of_match_device(usbhs_of_match, dev);
  400. u32 tmp;
  401. int gpio;
  402. info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
  403. if (!info)
  404. return NULL;
  405. dparam = &info->driver_param;
  406. dparam->type = of_id ? (u32)of_id->data : 0;
  407. if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp))
  408. dparam->buswait_bwait = tmp;
  409. gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0,
  410. NULL);
  411. if (gpio > 0)
  412. dparam->enable_gpio = gpio;
  413. return info;
  414. }
  415. static int usbhs_probe(struct platform_device *pdev)
  416. {
  417. struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev);
  418. struct renesas_usbhs_driver_callback *dfunc;
  419. struct usbhs_priv *priv;
  420. struct resource *res, *irq_res;
  421. int ret;
  422. /* check device node */
  423. if (pdev->dev.of_node)
  424. info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev);
  425. /* check platform information */
  426. if (!info) {
  427. dev_err(&pdev->dev, "no platform information\n");
  428. return -EINVAL;
  429. }
  430. /* platform data */
  431. irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  432. if (!irq_res) {
  433. dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n");
  434. return -ENODEV;
  435. }
  436. /* usb private data */
  437. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  438. if (!priv)
  439. return -ENOMEM;
  440. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  441. priv->base = devm_ioremap_resource(&pdev->dev, res);
  442. if (IS_ERR(priv->base))
  443. return PTR_ERR(priv->base);
  444. if (of_property_read_bool(pdev->dev.of_node, "extcon")) {
  445. priv->edev = extcon_get_edev_by_phandle(&pdev->dev, 0);
  446. if (IS_ERR(priv->edev))
  447. return PTR_ERR(priv->edev);
  448. }
  449. /*
  450. * care platform info
  451. */
  452. memcpy(&priv->dparam,
  453. &info->driver_param,
  454. sizeof(struct renesas_usbhs_driver_param));
  455. switch (priv->dparam.type) {
  456. case USBHS_TYPE_R8A7790:
  457. case USBHS_TYPE_R8A7791:
  458. priv->pfunc = usbhs_rcar2_ops;
  459. if (!priv->dparam.pipe_type) {
  460. priv->dparam.pipe_type = usbhsc_new_pipe_type;
  461. priv->dparam.pipe_size =
  462. ARRAY_SIZE(usbhsc_new_pipe_type);
  463. }
  464. break;
  465. default:
  466. if (!info->platform_callback.get_id) {
  467. dev_err(&pdev->dev, "no platform callbacks");
  468. return -EINVAL;
  469. }
  470. memcpy(&priv->pfunc,
  471. &info->platform_callback,
  472. sizeof(struct renesas_usbhs_platform_callback));
  473. break;
  474. }
  475. /* set driver callback functions for platform */
  476. dfunc = &info->driver_callback;
  477. dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug;
  478. /* set default param if platform doesn't have */
  479. if (!priv->dparam.pipe_type) {
  480. priv->dparam.pipe_type = usbhsc_default_pipe_type;
  481. priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type);
  482. }
  483. if (!priv->dparam.pio_dma_border)
  484. priv->dparam.pio_dma_border = 64; /* 64byte */
  485. /* FIXME */
  486. /* runtime power control ? */
  487. if (priv->pfunc.get_vbus)
  488. usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL);
  489. /*
  490. * priv settings
  491. */
  492. priv->irq = irq_res->start;
  493. if (irq_res->flags & IORESOURCE_IRQ_SHAREABLE)
  494. priv->irqflags = IRQF_SHARED;
  495. priv->pdev = pdev;
  496. INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug);
  497. spin_lock_init(usbhs_priv_to_lock(priv));
  498. /* call pipe and module init */
  499. ret = usbhs_pipe_probe(priv);
  500. if (ret < 0)
  501. return ret;
  502. ret = usbhs_fifo_probe(priv);
  503. if (ret < 0)
  504. goto probe_end_pipe_exit;
  505. ret = usbhs_mod_probe(priv);
  506. if (ret < 0)
  507. goto probe_end_fifo_exit;
  508. /* dev_set_drvdata should be called after usbhs_mod_init */
  509. platform_set_drvdata(pdev, priv);
  510. /*
  511. * deviece reset here because
  512. * USB device might be used in boot loader.
  513. */
  514. usbhs_sys_clock_ctrl(priv, 0);
  515. /* check GPIO determining if USB function should be enabled */
  516. if (priv->dparam.enable_gpio) {
  517. gpio_request_one(priv->dparam.enable_gpio, GPIOF_IN, NULL);
  518. ret = !gpio_get_value(priv->dparam.enable_gpio);
  519. gpio_free(priv->dparam.enable_gpio);
  520. if (ret) {
  521. dev_warn(&pdev->dev,
  522. "USB function not selected (GPIO %d)\n",
  523. priv->dparam.enable_gpio);
  524. ret = -ENOTSUPP;
  525. goto probe_end_mod_exit;
  526. }
  527. }
  528. /*
  529. * platform call
  530. *
  531. * USB phy setup might depend on CPU/Board.
  532. * If platform has its callback functions,
  533. * call it here.
  534. */
  535. ret = usbhs_platform_call(priv, hardware_init, pdev);
  536. if (ret < 0) {
  537. dev_err(&pdev->dev, "platform init failed.\n");
  538. goto probe_end_mod_exit;
  539. }
  540. /* reset phy for connection */
  541. usbhs_platform_call(priv, phy_reset, pdev);
  542. /* power control */
  543. pm_runtime_enable(&pdev->dev);
  544. if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) {
  545. usbhsc_power_ctrl(priv, 1);
  546. usbhs_mod_autonomy_mode(priv);
  547. }
  548. /*
  549. * manual call notify_hotplug for cold plug
  550. */
  551. usbhsc_drvcllbck_notify_hotplug(pdev);
  552. dev_info(&pdev->dev, "probed\n");
  553. return ret;
  554. probe_end_mod_exit:
  555. usbhs_mod_remove(priv);
  556. probe_end_fifo_exit:
  557. usbhs_fifo_remove(priv);
  558. probe_end_pipe_exit:
  559. usbhs_pipe_remove(priv);
  560. dev_info(&pdev->dev, "probe failed\n");
  561. return ret;
  562. }
  563. static int usbhs_remove(struct platform_device *pdev)
  564. {
  565. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  566. struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev);
  567. struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback;
  568. dev_dbg(&pdev->dev, "usb remove\n");
  569. dfunc->notify_hotplug = NULL;
  570. /* power off */
  571. if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
  572. usbhsc_power_ctrl(priv, 0);
  573. pm_runtime_disable(&pdev->dev);
  574. usbhs_platform_call(priv, hardware_exit, pdev);
  575. usbhs_mod_remove(priv);
  576. usbhs_fifo_remove(priv);
  577. usbhs_pipe_remove(priv);
  578. return 0;
  579. }
  580. static int usbhsc_suspend(struct device *dev)
  581. {
  582. struct usbhs_priv *priv = dev_get_drvdata(dev);
  583. struct usbhs_mod *mod = usbhs_mod_get_current(priv);
  584. if (mod) {
  585. usbhs_mod_call(priv, stop, priv);
  586. usbhs_mod_change(priv, -1);
  587. }
  588. if (mod || !usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
  589. usbhsc_power_ctrl(priv, 0);
  590. return 0;
  591. }
  592. static int usbhsc_resume(struct device *dev)
  593. {
  594. struct usbhs_priv *priv = dev_get_drvdata(dev);
  595. struct platform_device *pdev = usbhs_priv_to_pdev(priv);
  596. if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
  597. usbhsc_power_ctrl(priv, 1);
  598. usbhs_platform_call(priv, phy_reset, pdev);
  599. usbhsc_drvcllbck_notify_hotplug(pdev);
  600. return 0;
  601. }
  602. static int usbhsc_runtime_nop(struct device *dev)
  603. {
  604. /* Runtime PM callback shared between ->runtime_suspend()
  605. * and ->runtime_resume(). Simply returns success.
  606. *
  607. * This driver re-initializes all registers after
  608. * pm_runtime_get_sync() anyway so there is no need
  609. * to save and restore registers here.
  610. */
  611. return 0;
  612. }
  613. static const struct dev_pm_ops usbhsc_pm_ops = {
  614. .suspend = usbhsc_suspend,
  615. .resume = usbhsc_resume,
  616. .runtime_suspend = usbhsc_runtime_nop,
  617. .runtime_resume = usbhsc_runtime_nop,
  618. };
  619. static struct platform_driver renesas_usbhs_driver = {
  620. .driver = {
  621. .name = "renesas_usbhs",
  622. .pm = &usbhsc_pm_ops,
  623. .of_match_table = of_match_ptr(usbhs_of_match),
  624. },
  625. .probe = usbhs_probe,
  626. .remove = usbhs_remove,
  627. };
  628. module_platform_driver(renesas_usbhs_driver);
  629. MODULE_LICENSE("GPL");
  630. MODULE_DESCRIPTION("Renesas USB driver");
  631. MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");