diff options
author | Andres Salomon <dilinger@queued.net> | 2012-07-13 18:54:25 -0400 |
---|---|---|
committer | Andres Salomon <dilinger@queued.net> | 2012-07-31 23:27:30 -0400 |
commit | d278b7a2f90f91f908b19b50cfa59e10632b5afc (patch) | |
tree | 559ebe7c5cfbdb46381ecd9074dff292c09f7012 /drivers/platform | |
parent | ac2504151f5af27bbf0c0362b7da5951e05dfc43 (diff) |
Platform: OLPC: add a suspended flag to the EC driver
A problem we've noticed on XO-1.75 is when we suspend in the middle of
an EC command. Don't allow that.
In the process, create a private object for the generic EC driver to use;
we have a framework for passing around a struct, use that rather than a
proliferation of global variables.
Signed-off-by: Andres Salomon <dilinger@queued.net>
Acked-by: Paul Fox <pgf@laptop.org>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/platform')
-rw-r--r-- | drivers/platform/olpc/olpc-ec.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c index d00523c65191..cfba41fb04de 100644 --- a/drivers/platform/olpc/olpc-ec.c +++ b/drivers/platform/olpc/olpc-ec.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/spinlock.h> | 9 | #include <linux/spinlock.h> |
10 | #include <linux/mutex.h> | 10 | #include <linux/mutex.h> |
11 | #include <linux/platform_device.h> | 11 | #include <linux/platform_device.h> |
12 | #include <linux/slab.h> | ||
12 | #include <linux/workqueue.h> | 13 | #include <linux/workqueue.h> |
13 | #include <linux/module.h> | 14 | #include <linux/module.h> |
14 | #include <linux/list.h> | 15 | #include <linux/list.h> |
@@ -27,6 +28,21 @@ struct ec_cmd_desc { | |||
27 | void *priv; | 28 | void *priv; |
28 | }; | 29 | }; |
29 | 30 | ||
31 | struct olpc_ec_priv { | ||
32 | struct olpc_ec_driver *drv; | ||
33 | |||
34 | /* | ||
35 | * Running an EC command while suspending means we don't always finish | ||
36 | * the command before the machine suspends. This means that the EC | ||
37 | * is expecting the command protocol to finish, but we after a period | ||
38 | * of time (while the OS is asleep) the EC times out and restarts its | ||
39 | * idle loop. Meanwhile, the OS wakes up, thinks it's still in the | ||
40 | * middle of the command protocol, starts throwing random things at | ||
41 | * the EC... and everyone's uphappy. | ||
42 | */ | ||
43 | bool suspended; | ||
44 | }; | ||
45 | |||
30 | static void olpc_ec_worker(struct work_struct *w); | 46 | static void olpc_ec_worker(struct work_struct *w); |
31 | 47 | ||
32 | static DECLARE_WORK(ec_worker, olpc_ec_worker); | 48 | static DECLARE_WORK(ec_worker, olpc_ec_worker); |
@@ -34,6 +50,7 @@ static LIST_HEAD(ec_cmd_q); | |||
34 | static DEFINE_SPINLOCK(ec_cmd_q_lock); | 50 | static DEFINE_SPINLOCK(ec_cmd_q_lock); |
35 | 51 | ||
36 | static struct olpc_ec_driver *ec_driver; | 52 | static struct olpc_ec_driver *ec_driver; |
53 | static struct olpc_ec_priv *ec_priv; | ||
37 | static void *ec_cb_arg; | 54 | static void *ec_cb_arg; |
38 | static DEFINE_MUTEX(ec_cb_lock); | 55 | static DEFINE_MUTEX(ec_cb_lock); |
39 | 56 | ||
@@ -93,6 +110,7 @@ static void queue_ec_descriptor(struct ec_cmd_desc *desc) | |||
93 | 110 | ||
94 | int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen) | 111 | int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen) |
95 | { | 112 | { |
113 | struct olpc_ec_priv *ec = ec_priv; | ||
96 | struct ec_cmd_desc desc; | 114 | struct ec_cmd_desc desc; |
97 | 115 | ||
98 | /* XXX: this will be removed in later patches */ | 116 | /* XXX: this will be removed in later patches */ |
@@ -104,6 +122,13 @@ int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen) | |||
104 | if (WARN_ON(!ec_driver || !ec_driver->ec_cmd)) | 122 | if (WARN_ON(!ec_driver || !ec_driver->ec_cmd)) |
105 | return -ENODEV; | 123 | return -ENODEV; |
106 | 124 | ||
125 | if (!ec) | ||
126 | return -ENOMEM; | ||
127 | |||
128 | /* Suspending in the middle of a command hoses things really badly */ | ||
129 | if (WARN_ON(ec->suspended)) | ||
130 | return -EBUSY; | ||
131 | |||
107 | might_sleep(); | 132 | might_sleep(); |
108 | 133 | ||
109 | desc.cmd = cmd; | 134 | desc.cmd = cmd; |
@@ -126,11 +151,19 @@ EXPORT_SYMBOL_GPL(olpc_ec_cmd); | |||
126 | 151 | ||
127 | static int olpc_ec_probe(struct platform_device *pdev) | 152 | static int olpc_ec_probe(struct platform_device *pdev) |
128 | { | 153 | { |
154 | struct olpc_ec_priv *ec; | ||
129 | int err; | 155 | int err; |
130 | 156 | ||
131 | if (!ec_driver) | 157 | if (!ec_driver) |
132 | return -ENODEV; | 158 | return -ENODEV; |
133 | 159 | ||
160 | ec = kzalloc(sizeof(*ec), GFP_KERNEL); | ||
161 | if (!ec) | ||
162 | return -ENOMEM; | ||
163 | ec->drv = ec_driver; | ||
164 | ec_priv = ec; | ||
165 | platform_set_drvdata(pdev, ec); | ||
166 | |||
134 | err = ec_driver->probe ? ec_driver->probe(pdev) : 0; | 167 | err = ec_driver->probe ? ec_driver->probe(pdev) : 0; |
135 | 168 | ||
136 | return err; | 169 | return err; |
@@ -139,12 +172,23 @@ static int olpc_ec_probe(struct platform_device *pdev) | |||
139 | static int olpc_ec_suspend(struct device *dev) | 172 | static int olpc_ec_suspend(struct device *dev) |
140 | { | 173 | { |
141 | struct platform_device *pdev = to_platform_device(dev); | 174 | struct platform_device *pdev = to_platform_device(dev); |
142 | return ec_driver->suspend ? ec_driver->suspend(pdev) : 0; | 175 | struct olpc_ec_priv *ec = platform_get_drvdata(pdev); |
176 | int err = 0; | ||
177 | |||
178 | if (ec_driver->suspend) | ||
179 | err = ec_driver->suspend(pdev); | ||
180 | if (!err) | ||
181 | ec->suspended = true; | ||
182 | |||
183 | return err; | ||
143 | } | 184 | } |
144 | 185 | ||
145 | static int olpc_ec_resume(struct device *dev) | 186 | static int olpc_ec_resume(struct device *dev) |
146 | { | 187 | { |
147 | struct platform_device *pdev = to_platform_device(dev); | 188 | struct platform_device *pdev = to_platform_device(dev); |
189 | struct olpc_ec_priv *ec = platform_get_drvdata(pdev); | ||
190 | |||
191 | ec->suspended = false; | ||
148 | return ec_driver->resume ? ec_driver->resume(pdev) : 0; | 192 | return ec_driver->resume ? ec_driver->resume(pdev) : 0; |
149 | } | 193 | } |
150 | 194 | ||