summaryrefslogtreecommitdiff
path: root/drivers/hwmon/lsm303dlh_m.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lsm303dlh_m.c')
-rw-r--r--drivers/hwmon/lsm303dlh_m.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/drivers/hwmon/lsm303dlh_m.c b/drivers/hwmon/lsm303dlh_m.c
index aa43d055e67..ff7cfa428ea 100644
--- a/drivers/hwmon/lsm303dlh_m.c
+++ b/drivers/hwmon/lsm303dlh_m.c
@@ -38,6 +38,7 @@
#include <linux/lsm303dlh.h>
#include <linux/regulator/consumer.h>
+#include <linux/earlysuspend.h>
#include <linux/kernel.h>
/* lsm303dlh magnetometer registers */
@@ -129,6 +130,9 @@
#define DEVICE_ON 1
#define DEVICE_SUSPENDED 2
+/* device CHIP ID defines */
+#define LSM303DLHC_CHIP_ID 51
+
/**
* struct lsm303dlh_m_data - data structure used by lsm303dlh_m driver
* @client: i2c client
@@ -160,6 +164,7 @@ struct lsm303dlh_m_data {
unsigned char mode;
unsigned char rate;
unsigned char range;
+ struct early_suspend early_suspend;
int device_status;
};
@@ -333,16 +338,16 @@ static int lsm303dlh_m_xyz_read(struct lsm303dlh_m_data *ddata)
ddata->data[2] = (short)
(((xyz_data[4]) << 8) | xyz_data[5]);
-#ifdef SENSORS_LSM303DLHC
- /*
- * the out registers are in x, z and y order
- * so swap y and z values
- */
- temp = ddata->data[1];
- ddata->data[1] = ddata->data[2];
- ddata->data[2] = temp;
-#endif
-
+ /* check if chip is DHLC */
+ if (ddata->pdata.chip_id == LSM303DLHC_CHIP_ID) {
+ /*
+ * the out registers are in x, z and y order
+ * so swap y and z values
+ */
+ temp = ddata->data[1];
+ ddata->data[1] = ddata->data[2];
+ ddata->data[2] = temp;
+ }
/* taking orientation of x,y,z axis into account*/
ddata->data[ddata->pdata.axis_map_x] = ddata->pdata.negative_x ?
@@ -515,6 +520,7 @@ static ssize_t lsm303dlh_m_store_range(struct device *dev,
z_gain = Z_GAIN_8_1;
break;
default:
+ mutex_unlock(&ddata->lock);
return -EINVAL;
}
@@ -689,6 +695,12 @@ static int __devinit lsm303dlh_m_probe(struct i2c_client *client,
}
if (ddata->regulator) {
+ /*
+ * 0.83 milliamps typical with magnetic sensor setting ODR =
+ * 7.5 Hz, Accelerometer sensor ODR = 50 Hz. Double for
+ * safety.
+ */
+ regulator_set_optimum_mode(ddata->regulator, 830 * 2);
regulator_enable(ddata->regulator);
ddata->device_status = DEVICE_ON;
}