Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 343073
b: refs/heads/master
c: 7a7d6d9
h: refs/heads/master
i:
  343071: 0f338e7
v: v3
  • Loading branch information
Benjamin Tissoires authored and Jiri Kosina committed Dec 12, 2012
1 parent f8a7fc6 commit c4ad01e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9afd09a1db93cc9084846c2b9bc0d1194743e5dc
refs/heads/master: 7a7d6d9c5fcd4b674da38e814cfc0724c67731b2
14 changes: 11 additions & 3 deletions trunk/drivers/hid/i2c-hid/i2c-hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/hid.h>
#include <linux/mutex.h>

#include <linux/i2c/i2c-hid.h>

Expand Down Expand Up @@ -117,6 +118,8 @@ static const struct i2c_hid_cmd hid_set_power_cmd = { I2C_HID_CMD(0x08) };
* static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) };
*/

static DEFINE_MUTEX(i2c_hid_open_mut);

/* The main device structure */
struct i2c_hid {
struct i2c_client *client; /* i2c client */
Expand Down Expand Up @@ -641,17 +644,20 @@ static int i2c_hid_open(struct hid_device *hid)
{
struct i2c_client *client = hid->driver_data;
struct i2c_hid *ihid = i2c_get_clientdata(client);
int ret;
int ret = 0;

mutex_lock(&i2c_hid_open_mut);
if (!hid->open++) {
ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
if (ret) {
hid->open--;
return -EIO;
goto done;
}
set_bit(I2C_HID_STARTED, &ihid->flags);
}
return 0;
done:
mutex_unlock(&i2c_hid_open_mut);
return ret;
}

static void i2c_hid_close(struct hid_device *hid)
Expand All @@ -663,12 +669,14 @@ static void i2c_hid_close(struct hid_device *hid)
* data acquistion due to a resumption we no longer
* care about
*/
mutex_lock(&i2c_hid_open_mut);
if (!--hid->open) {
clear_bit(I2C_HID_STARTED, &ihid->flags);

/* Save some power */
i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
}
mutex_unlock(&i2c_hid_open_mut);
}

static int i2c_hid_power(struct hid_device *hid, int lvl)
Expand Down

0 comments on commit c4ad01e

Please sign in to comment.