Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99ecb01c authored by Andres Salomon's avatar Andres Salomon
Browse files

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: default avatarAndres Salomon <dilinger@queued.net>
Acked-by: default avatarPaul Fox <pgf@laptop.org>
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 6cca83d4
Loading
Loading
Loading
Loading
+28 −20
Original line number Original line Diff line number Diff line
@@ -31,6 +31,12 @@ struct ec_cmd_desc {


struct olpc_ec_priv {
struct olpc_ec_priv {
	struct olpc_ec_driver *drv;
	struct olpc_ec_driver *drv;
	struct work_struct worker;
	struct mutex cmd_lock;

	/* Pending EC commands */
	struct list_head cmd_q;
	spinlock_t cmd_q_lock;


	struct dentry *dbgfs_dir;
	struct dentry *dbgfs_dir;


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


static void olpc_ec_worker(struct work_struct *w);

static DECLARE_WORK(ec_worker, olpc_ec_worker);
static LIST_HEAD(ec_cmd_q);
static DEFINE_SPINLOCK(ec_cmd_q_lock);

static struct olpc_ec_driver *ec_driver;
static struct olpc_ec_driver *ec_driver;
static struct olpc_ec_priv *ec_priv;
static struct olpc_ec_priv *ec_priv;
static void *ec_cb_arg;
static void *ec_cb_arg;
static DEFINE_MUTEX(ec_cb_lock);


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


static void olpc_ec_worker(struct work_struct *w)
static void olpc_ec_worker(struct work_struct *w)
{
{
	struct olpc_ec_priv *ec = container_of(w, struct olpc_ec_priv, worker);
	struct ec_cmd_desc *desc = NULL;
	struct ec_cmd_desc *desc = NULL;
	unsigned long flags;
	unsigned long flags;


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


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


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


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


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


/*
/*
 * Throw a cmd descripter onto the list.  We now have SMP OLPC machines, so
 * Throw a cmd descripter onto the list.  We now have SMP OLPC machines, so
 * locking is pretty critical.
 * locking is pretty critical.
 */
 */
static void queue_ec_descriptor(struct ec_cmd_desc *desc)
static void queue_ec_descriptor(struct ec_cmd_desc *desc,
		struct olpc_ec_priv *ec)
{
{
	unsigned long flags;
	unsigned long flags;


	INIT_LIST_HEAD(&desc->node);
	INIT_LIST_HEAD(&desc->node);


	spin_lock_irqsave(&ec_cmd_q_lock, flags);
	spin_lock_irqsave(&ec->cmd_q_lock, flags);
	list_add_tail(&desc->node, &ec_cmd_q);
	list_add_tail(&desc->node, &ec->cmd_q);
	spin_unlock_irqrestore(&ec_cmd_q_lock, flags);
	spin_unlock_irqrestore(&ec->cmd_q_lock, flags);


	schedule_work(&ec_worker);
	schedule_work(&ec->worker);
}
}


int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen)
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)
	desc.err = 0;
	desc.err = 0;
	init_completion(&desc.finished);
	init_completion(&desc.finished);


	queue_ec_descriptor(&desc);
	queue_ec_descriptor(&desc, ec);


	/* Timeouts must be handled in the platform-specific EC hook */
	/* Timeouts must be handled in the platform-specific EC hook */
	wait_for_completion(&desc.finished);
	wait_for_completion(&desc.finished);
@@ -266,7 +267,14 @@ static int olpc_ec_probe(struct platform_device *pdev)
	ec = kzalloc(sizeof(*ec), GFP_KERNEL);
	ec = kzalloc(sizeof(*ec), GFP_KERNEL);
	if (!ec)
	if (!ec)
		return -ENOMEM;
		return -ENOMEM;

	ec->drv = ec_driver;
	ec->drv = ec_driver;
	INIT_WORK(&ec->worker, olpc_ec_worker);
	mutex_init(&ec->cmd_lock);

	INIT_LIST_HEAD(&ec->cmd_q);
	spin_lock_init(&ec->cmd_q_lock);

	ec_priv = ec;
	ec_priv = ec;
	platform_set_drvdata(pdev, ec);
	platform_set_drvdata(pdev, ec);