Skip to content

Commit

Permalink
mfd: cros_ec: move locking into cros_ec_cmd_xfer
Browse files Browse the repository at this point in the history
Now that there's a central cros_ec_cmd_xfer(), move the locking
out of the SPI driver.

Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Reviewed-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
  • Loading branch information
Andrew Bresticker authored and Lee Jones committed Oct 6, 2014
1 parent a6551a7 commit 6342753
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
10 changes: 9 additions & 1 deletion drivers/mfd/cros_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ EXPORT_SYMBOL(cros_ec_check_result);
int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg)
{
return ec_dev->cmd_xfer(ec_dev, msg);
int ret;

mutex_lock(&ec_dev->lock);
ret = ec_dev->cmd_xfer(ec_dev, msg);
mutex_unlock(&ec_dev->lock);

return ret;
}
EXPORT_SYMBOL(cros_ec_cmd_xfer);

Expand Down Expand Up @@ -98,6 +104,8 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
return -ENOMEM;
}

mutex_init(&ec_dev->lock);

err = mfd_add_devices(dev, 0, cros_devs,
ARRAY_SIZE(cros_devs),
NULL, ec_dev->irq, NULL);
Expand Down
11 changes: 0 additions & 11 deletions drivers/mfd/cros_ec_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@
* if no record
* @end_of_msg_delay: used to set the delay_usecs on the spi_transfer that
* is sent when we want to turn off CS at the end of a transaction.
* @lock: mutex to ensure only one user of cros_ec_cmd_xfer_spi at a time
*/
struct cros_ec_spi {
struct spi_device *spi;
s64 last_transfer_ns;
unsigned int end_of_msg_delay;
struct mutex lock;
};

static void debug_packet(struct device *dev, const char *name, u8 *ptr,
Expand Down Expand Up @@ -232,13 +230,6 @@ static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev,
int sum;
int ret = 0, final_ret;

/*
* We have the shared ec_dev buffer plus we do lots of separate spi_sync
* calls, so we need to make sure only one person is using this at a
* time.
*/
mutex_lock(&ec_spi->lock);

len = cros_ec_prepare_tx(ec_dev, ec_msg);
dev_dbg(ec_dev->dev, "prepared, len=%d\n", len);

Expand Down Expand Up @@ -327,7 +318,6 @@ static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev,
if (ec_msg->command == EC_CMD_REBOOT_EC)
msleep(EC_REBOOT_DELAY_MS);

mutex_unlock(&ec_spi->lock);
return ret;
}

Expand Down Expand Up @@ -359,7 +349,6 @@ static int cros_ec_spi_probe(struct spi_device *spi)
if (ec_spi == NULL)
return -ENOMEM;
ec_spi->spi = spi;
mutex_init(&ec_spi->lock);
ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
if (!ec_dev)
return -ENOMEM;
Expand Down

0 comments on commit 6342753

Please sign in to comment.