libahci_platform.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * AHCI SATA platform library
  3. *
  4. * Copyright 2004-2005 Red Hat, Inc.
  5. * Jeff Garzik <jgarzik@pobox.com>
  6. * Copyright 2010 MontaVista Software, LLC.
  7. * Anton Vorontsov <avorontsov@ru.mvista.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2, or (at your option)
  12. * any later version.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/kernel.h>
  16. #include <linux/gfp.h>
  17. #include <linux/module.h>
  18. #include <linux/pm.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/device.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/libata.h>
  23. #include <linux/ahci_platform.h>
  24. #include <linux/phy/phy.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/of_platform.h>
  27. #include "ahci.h"
  28. static void ahci_host_stop(struct ata_host *host);
  29. struct ata_port_operations ahci_platform_ops = {
  30. .inherits = &ahci_ops,
  31. .host_stop = ahci_host_stop,
  32. };
  33. EXPORT_SYMBOL_GPL(ahci_platform_ops);
  34. /**
  35. * ahci_platform_enable_phys - Enable PHYs
  36. * @hpriv: host private area to store config values
  37. *
  38. * This function enables all the PHYs found in hpriv->phys, if any.
  39. * If a PHY fails to be enabled, it disables all the PHYs already
  40. * enabled in reverse order and returns an error.
  41. *
  42. * RETURNS:
  43. * 0 on success otherwise a negative error code
  44. */
  45. static int ahci_platform_enable_phys(struct ahci_host_priv *hpriv)
  46. {
  47. int rc, i;
  48. for (i = 0; i < hpriv->nports; i++) {
  49. rc = phy_init(hpriv->phys[i]);
  50. if (rc)
  51. goto disable_phys;
  52. rc = phy_power_on(hpriv->phys[i]);
  53. if (rc) {
  54. phy_exit(hpriv->phys[i]);
  55. goto disable_phys;
  56. }
  57. }
  58. return 0;
  59. disable_phys:
  60. while (--i >= 0) {
  61. phy_power_off(hpriv->phys[i]);
  62. phy_exit(hpriv->phys[i]);
  63. }
  64. return rc;
  65. }
  66. /**
  67. * ahci_platform_disable_phys - Disable PHYs
  68. * @hpriv: host private area to store config values
  69. *
  70. * This function disables all PHYs found in hpriv->phys.
  71. */
  72. static void ahci_platform_disable_phys(struct ahci_host_priv *hpriv)
  73. {
  74. int i;
  75. for (i = 0; i < hpriv->nports; i++) {
  76. phy_power_off(hpriv->phys[i]);
  77. phy_exit(hpriv->phys[i]);
  78. }
  79. }
  80. /**
  81. * ahci_platform_enable_clks - Enable platform clocks
  82. * @hpriv: host private area to store config values
  83. *
  84. * This function enables all the clks found in hpriv->clks, starting at
  85. * index 0. If any clk fails to enable it disables all the clks already
  86. * enabled in reverse order, and then returns an error.
  87. *
  88. * RETURNS:
  89. * 0 on success otherwise a negative error code
  90. */
  91. int ahci_platform_enable_clks(struct ahci_host_priv *hpriv)
  92. {
  93. int c, rc;
  94. for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) {
  95. rc = clk_prepare_enable(hpriv->clks[c]);
  96. if (rc)
  97. goto disable_unprepare_clk;
  98. }
  99. return 0;
  100. disable_unprepare_clk:
  101. while (--c >= 0)
  102. clk_disable_unprepare(hpriv->clks[c]);
  103. return rc;
  104. }
  105. EXPORT_SYMBOL_GPL(ahci_platform_enable_clks);
  106. /**
  107. * ahci_platform_disable_clks - Disable platform clocks
  108. * @hpriv: host private area to store config values
  109. *
  110. * This function disables all the clks found in hpriv->clks, in reverse
  111. * order of ahci_platform_enable_clks (starting at the end of the array).
  112. */
  113. void ahci_platform_disable_clks(struct ahci_host_priv *hpriv)
  114. {
  115. int c;
  116. for (c = AHCI_MAX_CLKS - 1; c >= 0; c--)
  117. if (hpriv->clks[c])
  118. clk_disable_unprepare(hpriv->clks[c]);
  119. }
  120. EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
  121. /**
  122. * ahci_platform_enable_regulators - Enable regulators
  123. * @hpriv: host private area to store config values
  124. *
  125. * This function enables all the regulators found in
  126. * hpriv->target_pwrs, if any. If a regulator fails to be enabled, it
  127. * disables all the regulators already enabled in reverse order and
  128. * returns an error.
  129. *
  130. * RETURNS:
  131. * 0 on success otherwise a negative error code
  132. */
  133. int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv)
  134. {
  135. int rc, i;
  136. for (i = 0; i < hpriv->nports; i++) {
  137. if (!hpriv->target_pwrs[i])
  138. continue;
  139. rc = regulator_enable(hpriv->target_pwrs[i]);
  140. if (rc)
  141. goto disable_target_pwrs;
  142. }
  143. return 0;
  144. disable_target_pwrs:
  145. while (--i >= 0)
  146. if (hpriv->target_pwrs[i])
  147. regulator_disable(hpriv->target_pwrs[i]);
  148. return rc;
  149. }
  150. EXPORT_SYMBOL_GPL(ahci_platform_enable_regulators);
  151. /**
  152. * ahci_platform_disable_regulators - Disable regulators
  153. * @hpriv: host private area to store config values
  154. *
  155. * This function disables all regulators found in hpriv->target_pwrs.
  156. */
  157. void ahci_platform_disable_regulators(struct ahci_host_priv *hpriv)
  158. {
  159. int i;
  160. for (i = 0; i < hpriv->nports; i++) {
  161. if (!hpriv->target_pwrs[i])
  162. continue;
  163. regulator_disable(hpriv->target_pwrs[i]);
  164. }
  165. }
  166. EXPORT_SYMBOL_GPL(ahci_platform_disable_regulators);
  167. /**
  168. * ahci_platform_enable_resources - Enable platform resources
  169. * @hpriv: host private area to store config values
  170. *
  171. * This function enables all ahci_platform managed resources in the
  172. * following order:
  173. * 1) Regulator
  174. * 2) Clocks (through ahci_platform_enable_clks)
  175. * 3) Phys
  176. *
  177. * If resource enabling fails at any point the previous enabled resources
  178. * are disabled in reverse order.
  179. *
  180. * RETURNS:
  181. * 0 on success otherwise a negative error code
  182. */
  183. int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
  184. {
  185. int rc;
  186. rc = ahci_platform_enable_regulators(hpriv);
  187. if (rc)
  188. return rc;
  189. rc = ahci_platform_enable_clks(hpriv);
  190. if (rc)
  191. goto disable_regulator;
  192. rc = ahci_platform_enable_phys(hpriv);
  193. if (rc)
  194. goto disable_clks;
  195. return 0;
  196. disable_clks:
  197. ahci_platform_disable_clks(hpriv);
  198. disable_regulator:
  199. ahci_platform_disable_regulators(hpriv);
  200. return rc;
  201. }
  202. EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
  203. /**
  204. * ahci_platform_disable_resources - Disable platform resources
  205. * @hpriv: host private area to store config values
  206. *
  207. * This function disables all ahci_platform managed resources in the
  208. * following order:
  209. * 1) Phys
  210. * 2) Clocks (through ahci_platform_disable_clks)
  211. * 3) Regulator
  212. */
  213. void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
  214. {
  215. ahci_platform_disable_phys(hpriv);
  216. ahci_platform_disable_clks(hpriv);
  217. ahci_platform_disable_regulators(hpriv);
  218. }
  219. EXPORT_SYMBOL_GPL(ahci_platform_disable_resources);
  220. static void ahci_platform_put_resources(struct device *dev, void *res)
  221. {
  222. struct ahci_host_priv *hpriv = res;
  223. int c;
  224. if (hpriv->got_runtime_pm) {
  225. pm_runtime_put_sync(dev);
  226. pm_runtime_disable(dev);
  227. }
  228. for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++)
  229. clk_put(hpriv->clks[c]);
  230. /*
  231. * The regulators are tied to child node device and not to the
  232. * SATA device itself. So we can't use devm for automatically
  233. * releasing them. We have to do it manually here.
  234. */
  235. for (c = 0; c < hpriv->nports; c++)
  236. if (hpriv->target_pwrs && hpriv->target_pwrs[c])
  237. regulator_put(hpriv->target_pwrs[c]);
  238. kfree(hpriv->target_pwrs);
  239. }
  240. static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port,
  241. struct device *dev, struct device_node *node)
  242. {
  243. int rc;
  244. hpriv->phys[port] = devm_of_phy_get(dev, node, NULL);
  245. if (!IS_ERR(hpriv->phys[port]))
  246. return 0;
  247. rc = PTR_ERR(hpriv->phys[port]);
  248. switch (rc) {
  249. case -ENOSYS:
  250. /* No PHY support. Check if PHY is required. */
  251. if (of_find_property(node, "phys", NULL)) {
  252. dev_err(dev,
  253. "couldn't get PHY in node %s: ENOSYS\n",
  254. node->name);
  255. break;
  256. }
  257. case -ENODEV:
  258. /* continue normally */
  259. hpriv->phys[port] = NULL;
  260. rc = 0;
  261. break;
  262. default:
  263. dev_err(dev,
  264. "couldn't get PHY in node %s: %d\n",
  265. node->name, rc);
  266. break;
  267. }
  268. return rc;
  269. }
  270. static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port,
  271. struct device *dev)
  272. {
  273. struct regulator *target_pwr;
  274. int rc = 0;
  275. target_pwr = regulator_get_optional(dev, "target");
  276. if (!IS_ERR(target_pwr))
  277. hpriv->target_pwrs[port] = target_pwr;
  278. else
  279. rc = PTR_ERR(target_pwr);
  280. return rc;
  281. }
  282. /**
  283. * ahci_platform_get_resources - Get platform resources
  284. * @pdev: platform device to get resources for
  285. *
  286. * This function allocates an ahci_host_priv struct, and gets the following
  287. * resources, storing a reference to them inside the returned struct:
  288. *
  289. * 1) mmio registers (IORESOURCE_MEM 0, mandatory)
  290. * 2) regulator for controlling the targets power (optional)
  291. * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
  292. * or for non devicetree enabled platforms a single clock
  293. * 4) phys (optional)
  294. *
  295. * RETURNS:
  296. * The allocated ahci_host_priv on success, otherwise an ERR_PTR value
  297. */
  298. struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev)
  299. {
  300. struct device *dev = &pdev->dev;
  301. struct ahci_host_priv *hpriv;
  302. struct clk *clk;
  303. struct device_node *child;
  304. int i, sz, enabled_ports = 0, rc = -ENOMEM, child_nodes;
  305. u32 mask_port_map = 0;
  306. if (!devres_open_group(dev, NULL, GFP_KERNEL))
  307. return ERR_PTR(-ENOMEM);
  308. hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv),
  309. GFP_KERNEL);
  310. if (!hpriv)
  311. goto err_out;
  312. devres_add(dev, hpriv);
  313. hpriv->mmio = devm_ioremap_resource(dev,
  314. platform_get_resource(pdev, IORESOURCE_MEM, 0));
  315. if (IS_ERR(hpriv->mmio)) {
  316. dev_err(dev, "no mmio space\n");
  317. rc = PTR_ERR(hpriv->mmio);
  318. goto err_out;
  319. }
  320. for (i = 0; i < AHCI_MAX_CLKS; i++) {
  321. /*
  322. * For now we must use clk_get(dev, NULL) for the first clock,
  323. * because some platforms (da850, spear13xx) are not yet
  324. * converted to use devicetree for clocks. For new platforms
  325. * this is equivalent to of_clk_get(dev->of_node, 0).
  326. */
  327. if (i == 0)
  328. clk = clk_get(dev, NULL);
  329. else
  330. clk = of_clk_get(dev->of_node, i);
  331. if (IS_ERR(clk)) {
  332. rc = PTR_ERR(clk);
  333. if (rc == -EPROBE_DEFER)
  334. goto err_out;
  335. break;
  336. }
  337. hpriv->clks[i] = clk;
  338. }
  339. hpriv->nports = child_nodes = of_get_child_count(dev->of_node);
  340. /*
  341. * If no sub-node was found, we still need to set nports to
  342. * one in order to be able to use the
  343. * ahci_platform_[en|dis]able_[phys|regulators] functions.
  344. */
  345. if (!child_nodes)
  346. hpriv->nports = 1;
  347. sz = hpriv->nports * sizeof(*hpriv->phys);
  348. hpriv->phys = devm_kzalloc(dev, sz, GFP_KERNEL);
  349. if (!hpriv->phys) {
  350. rc = -ENOMEM;
  351. goto err_out;
  352. }
  353. sz = hpriv->nports * sizeof(*hpriv->target_pwrs);
  354. hpriv->target_pwrs = kzalloc(sz, GFP_KERNEL);
  355. if (!hpriv->target_pwrs) {
  356. rc = -ENOMEM;
  357. goto err_out;
  358. }
  359. if (child_nodes) {
  360. for_each_child_of_node(dev->of_node, child) {
  361. u32 port;
  362. struct platform_device *port_dev __maybe_unused;
  363. if (!of_device_is_available(child))
  364. continue;
  365. if (of_property_read_u32(child, "reg", &port)) {
  366. rc = -EINVAL;
  367. goto err_out;
  368. }
  369. if (port >= hpriv->nports) {
  370. dev_warn(dev, "invalid port number %d\n", port);
  371. continue;
  372. }
  373. mask_port_map |= BIT(port);
  374. #ifdef CONFIG_OF_ADDRESS
  375. of_platform_device_create(child, NULL, NULL);
  376. port_dev = of_find_device_by_node(child);
  377. if (port_dev) {
  378. rc = ahci_platform_get_regulator(hpriv, port,
  379. &port_dev->dev);
  380. if (rc == -EPROBE_DEFER)
  381. goto err_out;
  382. }
  383. #endif
  384. rc = ahci_platform_get_phy(hpriv, port, dev, child);
  385. if (rc)
  386. goto err_out;
  387. enabled_ports++;
  388. }
  389. if (!enabled_ports) {
  390. dev_warn(dev, "No port enabled\n");
  391. rc = -ENODEV;
  392. goto err_out;
  393. }
  394. if (!hpriv->mask_port_map)
  395. hpriv->mask_port_map = mask_port_map;
  396. } else {
  397. /*
  398. * If no sub-node was found, keep this for device tree
  399. * compatibility
  400. */
  401. rc = ahci_platform_get_phy(hpriv, 0, dev, dev->of_node);
  402. if (rc)
  403. goto err_out;
  404. rc = ahci_platform_get_regulator(hpriv, 0, dev);
  405. if (rc == -EPROBE_DEFER)
  406. goto err_out;
  407. }
  408. pm_runtime_enable(dev);
  409. pm_runtime_get_sync(dev);
  410. hpriv->got_runtime_pm = true;
  411. devres_remove_group(dev, NULL);
  412. return hpriv;
  413. err_out:
  414. devres_release_group(dev, NULL);
  415. return ERR_PTR(rc);
  416. }
  417. EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
  418. /**
  419. * ahci_platform_init_host - Bring up an ahci-platform host
  420. * @pdev: platform device pointer for the host
  421. * @hpriv: ahci-host private data for the host
  422. * @pi_template: template for the ata_port_info to use
  423. * @sht: scsi_host_template to use when registering
  424. *
  425. * This function does all the usual steps needed to bring up an
  426. * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
  427. * must be initialized / enabled before calling this.
  428. *
  429. * RETURNS:
  430. * 0 on success otherwise a negative error code
  431. */
  432. int ahci_platform_init_host(struct platform_device *pdev,
  433. struct ahci_host_priv *hpriv,
  434. const struct ata_port_info *pi_template,
  435. struct scsi_host_template *sht)
  436. {
  437. struct device *dev = &pdev->dev;
  438. struct ata_port_info pi = *pi_template;
  439. const struct ata_port_info *ppi[] = { &pi, NULL };
  440. struct ata_host *host;
  441. int i, irq, n_ports, rc;
  442. irq = platform_get_irq(pdev, 0);
  443. if (irq <= 0) {
  444. if (irq != -EPROBE_DEFER)
  445. dev_err(dev, "no irq\n");
  446. return irq;
  447. }
  448. hpriv->irq = irq;
  449. /* prepare host */
  450. pi.private_data = (void *)(unsigned long)hpriv->flags;
  451. ahci_save_initial_config(dev, hpriv);
  452. if (hpriv->cap & HOST_CAP_NCQ)
  453. pi.flags |= ATA_FLAG_NCQ;
  454. if (hpriv->cap & HOST_CAP_PMP)
  455. pi.flags |= ATA_FLAG_PMP;
  456. ahci_set_em_messages(hpriv, &pi);
  457. /* CAP.NP sometimes indicate the index of the last enabled
  458. * port, at other times, that of the last possible port, so
  459. * determining the maximum port number requires looking at
  460. * both CAP.NP and port_map.
  461. */
  462. n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
  463. host = ata_host_alloc_pinfo(dev, ppi, n_ports);
  464. if (!host)
  465. return -ENOMEM;
  466. host->private_data = hpriv;
  467. if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
  468. host->flags |= ATA_HOST_PARALLEL_SCAN;
  469. else
  470. dev_info(dev, "SSS flag set, parallel bus scan disabled\n");
  471. if (pi.flags & ATA_FLAG_EM)
  472. ahci_reset_em(host);
  473. for (i = 0; i < host->n_ports; i++) {
  474. struct ata_port *ap = host->ports[i];
  475. ata_port_desc(ap, "mmio %pR",
  476. platform_get_resource(pdev, IORESOURCE_MEM, 0));
  477. ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
  478. /* set enclosure management message type */
  479. if (ap->flags & ATA_FLAG_EM)
  480. ap->em_message_type = hpriv->em_msg_type;
  481. /* disabled/not-implemented port */
  482. if (!(hpriv->port_map & (1 << i)))
  483. ap->ops = &ata_dummy_port_ops;
  484. }
  485. if (hpriv->cap & HOST_CAP_64) {
  486. rc = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64));
  487. if (rc) {
  488. rc = dma_coerce_mask_and_coherent(dev,
  489. DMA_BIT_MASK(32));
  490. if (rc) {
  491. dev_err(dev, "Failed to enable 64-bit DMA.\n");
  492. return rc;
  493. }
  494. dev_warn(dev, "Enable 32-bit DMA instead of 64-bit.\n");
  495. }
  496. }
  497. rc = ahci_reset_controller(host);
  498. if (rc)
  499. return rc;
  500. ahci_init_controller(host);
  501. ahci_print_info(host, "platform");
  502. return ahci_host_activate(host, sht);
  503. }
  504. EXPORT_SYMBOL_GPL(ahci_platform_init_host);
  505. static void ahci_host_stop(struct ata_host *host)
  506. {
  507. struct ahci_host_priv *hpriv = host->private_data;
  508. ahci_platform_disable_resources(hpriv);
  509. }
  510. #ifdef CONFIG_PM_SLEEP
  511. /**
  512. * ahci_platform_suspend_host - Suspend an ahci-platform host
  513. * @dev: device pointer for the host
  514. *
  515. * This function does all the usual steps needed to suspend an
  516. * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
  517. * must be disabled after calling this.
  518. *
  519. * RETURNS:
  520. * 0 on success otherwise a negative error code
  521. */
  522. int ahci_platform_suspend_host(struct device *dev)
  523. {
  524. struct ata_host *host = dev_get_drvdata(dev);
  525. struct ahci_host_priv *hpriv = host->private_data;
  526. void __iomem *mmio = hpriv->mmio;
  527. u32 ctl;
  528. if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
  529. dev_err(dev, "firmware update required for suspend/resume\n");
  530. return -EIO;
  531. }
  532. /*
  533. * AHCI spec rev1.1 section 8.3.3:
  534. * Software must disable interrupts prior to requesting a
  535. * transition of the HBA to D3 state.
  536. */
  537. ctl = readl(mmio + HOST_CTL);
  538. ctl &= ~HOST_IRQ_EN;
  539. writel(ctl, mmio + HOST_CTL);
  540. readl(mmio + HOST_CTL); /* flush */
  541. return ata_host_suspend(host, PMSG_SUSPEND);
  542. }
  543. EXPORT_SYMBOL_GPL(ahci_platform_suspend_host);
  544. /**
  545. * ahci_platform_resume_host - Resume an ahci-platform host
  546. * @dev: device pointer for the host
  547. *
  548. * This function does all the usual steps needed to resume an ahci-platform
  549. * host, note any necessary resources (ie clks, phys, etc.) must be
  550. * initialized / enabled before calling this.
  551. *
  552. * RETURNS:
  553. * 0 on success otherwise a negative error code
  554. */
  555. int ahci_platform_resume_host(struct device *dev)
  556. {
  557. struct ata_host *host = dev_get_drvdata(dev);
  558. int rc;
  559. if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
  560. rc = ahci_reset_controller(host);
  561. if (rc)
  562. return rc;
  563. ahci_init_controller(host);
  564. }
  565. ata_host_resume(host);
  566. return 0;
  567. }
  568. EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
  569. /**
  570. * ahci_platform_suspend - Suspend an ahci-platform device
  571. * @dev: the platform device to suspend
  572. *
  573. * This function suspends the host associated with the device, followed by
  574. * disabling all the resources of the device.
  575. *
  576. * RETURNS:
  577. * 0 on success otherwise a negative error code
  578. */
  579. int ahci_platform_suspend(struct device *dev)
  580. {
  581. struct ata_host *host = dev_get_drvdata(dev);
  582. struct ahci_host_priv *hpriv = host->private_data;
  583. int rc;
  584. rc = ahci_platform_suspend_host(dev);
  585. if (rc)
  586. return rc;
  587. ahci_platform_disable_resources(hpriv);
  588. return 0;
  589. }
  590. EXPORT_SYMBOL_GPL(ahci_platform_suspend);
  591. /**
  592. * ahci_platform_resume - Resume an ahci-platform device
  593. * @dev: the platform device to resume
  594. *
  595. * This function enables all the resources of the device followed by
  596. * resuming the host associated with the device.
  597. *
  598. * RETURNS:
  599. * 0 on success otherwise a negative error code
  600. */
  601. int ahci_platform_resume(struct device *dev)
  602. {
  603. struct ata_host *host = dev_get_drvdata(dev);
  604. struct ahci_host_priv *hpriv = host->private_data;
  605. int rc;
  606. rc = ahci_platform_enable_resources(hpriv);
  607. if (rc)
  608. return rc;
  609. rc = ahci_platform_resume_host(dev);
  610. if (rc)
  611. goto disable_resources;
  612. /* We resumed so update PM runtime state */
  613. pm_runtime_disable(dev);
  614. pm_runtime_set_active(dev);
  615. pm_runtime_enable(dev);
  616. return 0;
  617. disable_resources:
  618. ahci_platform_disable_resources(hpriv);
  619. return rc;
  620. }
  621. EXPORT_SYMBOL_GPL(ahci_platform_resume);
  622. #endif
  623. MODULE_DESCRIPTION("AHCI SATA platform library");
  624. MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
  625. MODULE_LICENSE("GPL");