sunxi: driver refresh for 3.13
[openwrt.git] / target / linux / sunxi / patches-3.13 / 162-3-ahci-plat-runtime-resume.patch
1 From 48379fed3987d587a25a48e155872e9d3125490d Mon Sep 17 00:00:00 2001
2 From: Roger Quadros <rogerq@ti.com>
3 Date: Wed, 9 Oct 2013 15:08:59 +0300
4 Subject: [PATCH] ata: ahci_platform: runtime resume the device before use
5
6 On OMAP platforms the device needs to be runtime resumed before
7 it can be accessed. The OMAP HWMOD framework takes care of
8 enabling the module and its resources based on the
9 device's runtime PM state.
10
11 In this patch we runtime resume during .probe() and runtime suspend
12 after .remove().
13
14 We also update the runtime PM state during .resume().
15
16 CC: Balaji T K <balajitk@ti.com>
17 Signed-off-by: Roger Quadros <rogerq@ti.com>
18 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
19 ---
20  drivers/ata/ahci.h          |  1 +
21  drivers/ata/ahci_platform.c | 15 +++++++++++++++
22  2 files changed, 16 insertions(+)
23
24 diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
25 index 3ab7ac9..51af275b 100644
26 --- a/drivers/ata/ahci.h
27 +++ b/drivers/ata/ahci.h
28 @@ -324,6 +324,7 @@ struct ahci_host_priv {
29         u32                     em_loc; /* enclosure management location */
30         u32                     em_buf_sz;      /* EM buffer size in byte */
31         u32                     em_msg_type;    /* EM message type */
32 +       bool                    got_runtime_pm; /* Did we do pm_runtime_get? */
33         struct clk              *clks[AHCI_MAX_CLKS]; /* Optional */
34         struct regulator        *target_pwr;    /* Optional */
35         struct phy              *phy;           /* If platform uses phy */
36 diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
37 index 99d38c1..75698a4 100644
38 --- a/drivers/ata/ahci_platform.c
39 +++ b/drivers/ata/ahci_platform.c
40 @@ -24,6 +24,7 @@
41  #include <linux/libata.h>
42  #include <linux/ahci_platform.h>
43  #include <linux/phy/phy.h>
44 +#include <linux/pm_runtime.h>
45  #include "ahci.h"
46  
47  static void ahci_host_stop(struct ata_host *host);
48 @@ -229,6 +230,11 @@ static void ahci_platform_put_resources(struct device *dev, void *res)
49         struct ahci_host_priv *hpriv = res;
50         int c;
51  
52 +       if (hpriv->got_runtime_pm) {
53 +               pm_runtime_put_sync(dev);
54 +               pm_runtime_disable(dev);
55 +       }
56 +
57         for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++)
58                 clk_put(hpriv->clks[c]);
59  }
60 @@ -326,6 +332,10 @@ struct ahci_host_priv *ahci_platform_get_resources(
61                 }
62         }
63  
64 +       pm_runtime_enable(dev);
65 +       pm_runtime_get_sync(dev);
66 +       hpriv->got_runtime_pm = true;
67 +
68         devres_remove_group(dev, NULL);
69         return hpriv;
70  
71 @@ -635,6 +645,11 @@ int ahci_platform_resume(struct device *dev)
72         if (rc)
73                 goto disable_resources;
74  
75 +       /* We resumed so update PM runtime state */
76 +       pm_runtime_disable(dev);
77 +       pm_runtime_set_active(dev);
78 +       pm_runtime_enable(dev);
79 +
80         return 0;
81  
82  disable_resources:
83 -- 
84 1.8.5.5
85