Skip to content

Commit 99ecb01

Browse files
committed
Platform: OLPC: move global variables into priv struct
Populate olpc_ec_priv with variables that were previously global. This makes things a tad bit clearer, IMO. Signed-off-by: Andres Salomon <dilinger@queued.net> Acked-by: Paul Fox <pgf@laptop.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 6cca83d commit 99ecb01

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

drivers/platform/olpc/olpc-ec.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ struct ec_cmd_desc {
3131

3232
struct olpc_ec_priv {
3333
struct olpc_ec_driver *drv;
34+
struct work_struct worker;
35+
struct mutex cmd_lock;
36+
37+
/* Pending EC commands */
38+
struct list_head cmd_q;
39+
spinlock_t cmd_q_lock;
3440

3541
struct dentry *dbgfs_dir;
3642

@@ -46,16 +52,9 @@ struct olpc_ec_priv {
4652
bool suspended;
4753
};
4854

49-
static void olpc_ec_worker(struct work_struct *w);
50-
51-
static DECLARE_WORK(ec_worker, olpc_ec_worker);
52-
static LIST_HEAD(ec_cmd_q);
53-
static DEFINE_SPINLOCK(ec_cmd_q_lock);
54-
5555
static struct olpc_ec_driver *ec_driver;
5656
static struct olpc_ec_priv *ec_priv;
5757
static void *ec_cb_arg;
58-
static DEFINE_MUTEX(ec_cb_lock);
5958

6059
void olpc_ec_driver_register(struct olpc_ec_driver *drv, void *arg)
6160
{
@@ -66,49 +65,51 @@ EXPORT_SYMBOL_GPL(olpc_ec_driver_register);
6665

6766
static void olpc_ec_worker(struct work_struct *w)
6867
{
68+
struct olpc_ec_priv *ec = container_of(w, struct olpc_ec_priv, worker);
6969
struct ec_cmd_desc *desc = NULL;
7070
unsigned long flags;
7171

7272
/* Grab the first pending command from the queue */
73-
spin_lock_irqsave(&ec_cmd_q_lock, flags);
74-
if (!list_empty(&ec_cmd_q)) {
75-
desc = list_first_entry(&ec_cmd_q, struct ec_cmd_desc, node);
73+
spin_lock_irqsave(&ec->cmd_q_lock, flags);
74+
if (!list_empty(&ec->cmd_q)) {
75+
desc = list_first_entry(&ec->cmd_q, struct ec_cmd_desc, node);
7676
list_del(&desc->node);
7777
}
78-
spin_unlock_irqrestore(&ec_cmd_q_lock, flags);
78+
spin_unlock_irqrestore(&ec->cmd_q_lock, flags);
7979

8080
/* Do we actually have anything to do? */
8181
if (!desc)
8282
return;
8383

8484
/* Protect the EC hw with a mutex; only run one cmd at a time */
85-
mutex_lock(&ec_cb_lock);
85+
mutex_lock(&ec->cmd_lock);
8686
desc->err = ec_driver->ec_cmd(desc->cmd, desc->inbuf, desc->inlen,
8787
desc->outbuf, desc->outlen, ec_cb_arg);
88-
mutex_unlock(&ec_cb_lock);
88+
mutex_unlock(&ec->cmd_lock);
8989

9090
/* Finished, wake up olpc_ec_cmd() */
9191
complete(&desc->finished);
9292

9393
/* Run the worker thread again in case there are more cmds pending */
94-
schedule_work(&ec_worker);
94+
schedule_work(&ec->worker);
9595
}
9696

9797
/*
9898
* Throw a cmd descripter onto the list. We now have SMP OLPC machines, so
9999
* locking is pretty critical.
100100
*/
101-
static void queue_ec_descriptor(struct ec_cmd_desc *desc)
101+
static void queue_ec_descriptor(struct ec_cmd_desc *desc,
102+
struct olpc_ec_priv *ec)
102103
{
103104
unsigned long flags;
104105

105106
INIT_LIST_HEAD(&desc->node);
106107

107-
spin_lock_irqsave(&ec_cmd_q_lock, flags);
108-
list_add_tail(&desc->node, &ec_cmd_q);
109-
spin_unlock_irqrestore(&ec_cmd_q_lock, flags);
108+
spin_lock_irqsave(&ec->cmd_q_lock, flags);
109+
list_add_tail(&desc->node, &ec->cmd_q);
110+
spin_unlock_irqrestore(&ec->cmd_q_lock, flags);
110111

111-
schedule_work(&ec_worker);
112+
schedule_work(&ec->worker);
112113
}
113114

114115
int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen)
@@ -137,7 +138,7 @@ int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen)
137138
desc.err = 0;
138139
init_completion(&desc.finished);
139140

140-
queue_ec_descriptor(&desc);
141+
queue_ec_descriptor(&desc, ec);
141142

142143
/* Timeouts must be handled in the platform-specific EC hook */
143144
wait_for_completion(&desc.finished);
@@ -266,7 +267,14 @@ static int olpc_ec_probe(struct platform_device *pdev)
266267
ec = kzalloc(sizeof(*ec), GFP_KERNEL);
267268
if (!ec)
268269
return -ENOMEM;
270+
269271
ec->drv = ec_driver;
272+
INIT_WORK(&ec->worker, olpc_ec_worker);
273+
mutex_init(&ec->cmd_lock);
274+
275+
INIT_LIST_HEAD(&ec->cmd_q);
276+
spin_lock_init(&ec->cmd_q_lock);
277+
270278
ec_priv = ec;
271279
platform_set_drvdata(pdev, ec);
272280

0 commit comments

Comments
 (0)