Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 316023
b: refs/heads/master
c: edf48f3
h: refs/heads/master
i:
  316021: 1f9a7f8
  316019: dd168eb
  316015: f91c0d3
v: v3
  • Loading branch information
Henrik Rydberg authored and Guenter Roeck committed Jul 22, 2012
1 parent b23e444 commit 4612a0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 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: 0ef63e48f0247a9f9b9ffeef0f2641ac880728ab
refs/heads/master: edf48f3a73b027a99c92edab2b07d78fe77523cc
41 changes: 13 additions & 28 deletions trunk/drivers/hwmon/applesmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ static const char *const fan_speed_fmt[] = {
#define APPLESMC_INPUT_FUZZ 4 /* input event threshold */
#define APPLESMC_INPUT_FLAT 4

#define SENSOR_X 0
#define SENSOR_Y 1
#define SENSOR_Z 2

#define to_index(attr) (to_sensor_dev_attr(attr)->index & 0xffff)
#define to_option(attr) (to_sensor_dev_attr(attr)->index >> 16)

Expand Down Expand Up @@ -432,30 +428,19 @@ static int applesmc_has_key(const char *key, bool *value)
}

/*
* applesmc_read_motion_sensor - Read motion sensor (X, Y or Z).
* applesmc_read_s16 - Read 16-bit signed big endian register
*/
static int applesmc_read_motion_sensor(int index, s16 *value)
static int applesmc_read_s16(const char *key, s16 *value)
{
u8 buffer[2];
int ret;

switch (index) {
case SENSOR_X:
ret = applesmc_read_key(MOTION_SENSOR_X_KEY, buffer, 2);
break;
case SENSOR_Y:
ret = applesmc_read_key(MOTION_SENSOR_Y_KEY, buffer, 2);
break;
case SENSOR_Z:
ret = applesmc_read_key(MOTION_SENSOR_Z_KEY, buffer, 2);
break;
default:
ret = -EINVAL;
}
ret = applesmc_read_key(key, buffer, 2);
if (ret)
return ret;

*value = ((s16)buffer[0] << 8) | buffer[1];

return ret;
return 0;
}

/*
Expand Down Expand Up @@ -624,8 +609,8 @@ static struct platform_driver applesmc_driver = {
*/
static void applesmc_calibrate(void)
{
applesmc_read_motion_sensor(SENSOR_X, &rest_x);
applesmc_read_motion_sensor(SENSOR_Y, &rest_y);
applesmc_read_s16(MOTION_SENSOR_X_KEY, &rest_x);
applesmc_read_s16(MOTION_SENSOR_Y_KEY, &rest_y);
rest_x = -rest_x;
}

Expand All @@ -634,9 +619,9 @@ static void applesmc_idev_poll(struct input_polled_dev *dev)
struct input_dev *idev = dev->input;
s16 x, y;

if (applesmc_read_motion_sensor(SENSOR_X, &x))
if (applesmc_read_s16(MOTION_SENSOR_X_KEY, &x))
return;
if (applesmc_read_motion_sensor(SENSOR_Y, &y))
if (applesmc_read_s16(MOTION_SENSOR_Y_KEY, &y))
return;

x = -x;
Expand All @@ -659,13 +644,13 @@ static ssize_t applesmc_position_show(struct device *dev,
int ret;
s16 x, y, z;

ret = applesmc_read_motion_sensor(SENSOR_X, &x);
ret = applesmc_read_s16(MOTION_SENSOR_X_KEY, &x);
if (ret)
goto out;
ret = applesmc_read_motion_sensor(SENSOR_Y, &y);
ret = applesmc_read_s16(MOTION_SENSOR_Y_KEY, &y);
if (ret)
goto out;
ret = applesmc_read_motion_sensor(SENSOR_Z, &z);
ret = applesmc_read_s16(MOTION_SENSOR_Z_KEY, &z);
if (ret)
goto out;

Expand Down

0 comments on commit 4612a0d

Please sign in to comment.