Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: mpu3050 - configure the sampling method

This will improve the output of the sensor.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by

Heikki Krogerus and committed by
Dmitry Torokhov
cd314fa6 3b518724

+103 -5
+103 -5
drivers/input/misc/mpu3050.c
··· 41 41 #include <linux/slab.h> 42 42 #include <linux/pm_runtime.h> 43 43 44 - #define MPU3050_CHIP_ID_REG 0x00 45 44 #define MPU3050_CHIP_ID 0x69 46 - #define MPU3050_XOUT_H 0x1D 47 - #define MPU3050_PWR_MGM 0x3E 48 - #define MPU3050_PWR_MGM_POS 6 49 - #define MPU3050_PWR_MGM_MASK 0x40 50 45 51 46 #define MPU3050_AUTO_DELAY 1000 52 47 53 48 #define MPU3050_MIN_VALUE -32768 54 49 #define MPU3050_MAX_VALUE 32767 50 + 51 + #define MPU3050_DEFAULT_POLL_INTERVAL 200 52 + #define MPU3050_DEFAULT_FS_RANGE 3 53 + 54 + /* Register map */ 55 + #define MPU3050_CHIP_ID_REG 0x00 56 + #define MPU3050_SMPLRT_DIV 0x15 57 + #define MPU3050_DLPF_FS_SYNC 0x16 58 + #define MPU3050_INT_CFG 0x17 59 + #define MPU3050_XOUT_H 0x1D 60 + #define MPU3050_PWR_MGM 0x3E 61 + #define MPU3050_PWR_MGM_POS 6 62 + 63 + /* Register bits */ 64 + 65 + /* DLPF_FS_SYNC */ 66 + #define MPU3050_EXT_SYNC_NONE 0x00 67 + #define MPU3050_EXT_SYNC_TEMP 0x20 68 + #define MPU3050_EXT_SYNC_GYROX 0x40 69 + #define MPU3050_EXT_SYNC_GYROY 0x60 70 + #define MPU3050_EXT_SYNC_GYROZ 0x80 71 + #define MPU3050_EXT_SYNC_ACCELX 0xA0 72 + #define MPU3050_EXT_SYNC_ACCELY 0xC0 73 + #define MPU3050_EXT_SYNC_ACCELZ 0xE0 74 + #define MPU3050_EXT_SYNC_MASK 0xE0 75 + #define MPU3050_FS_250DPS 0x00 76 + #define MPU3050_FS_500DPS 0x08 77 + #define MPU3050_FS_1000DPS 0x10 78 + #define MPU3050_FS_2000DPS 0x18 79 + #define MPU3050_FS_MASK 0x18 80 + #define MPU3050_DLPF_CFG_256HZ_NOLPF2 0x00 81 + #define MPU3050_DLPF_CFG_188HZ 0x01 82 + #define MPU3050_DLPF_CFG_98HZ 0x02 83 + #define MPU3050_DLPF_CFG_42HZ 0x03 84 + #define MPU3050_DLPF_CFG_20HZ 0x04 85 + #define MPU3050_DLPF_CFG_10HZ 0x05 86 + #define MPU3050_DLPF_CFG_5HZ 0x06 87 + #define MPU3050_DLPF_CFG_2100HZ_NOLPF 0x07 88 + #define MPU3050_DLPF_CFG_MASK 0x07 89 + /* INT_CFG */ 90 + #define MPU3050_RAW_RDY_EN 0x01 91 + #define MPU3050_MPU_RDY_EN 0x02 92 + #define MPU3050_LATCH_INT_EN 0x04 93 + /* PWR_MGM */ 94 + #define MPU3050_PWR_MGM_PLL_X 0x01 95 + #define MPU3050_PWR_MGM_PLL_Y 0x02 96 + #define MPU3050_PWR_MGM_PLL_Z 0x03 97 + #define MPU3050_PWR_MGM_CLKSEL 0x07 98 + #define MPU3050_PWR_MGM_STBY_ZG 0x08 99 + #define MPU3050_PWR_MGM_STBY_YG 0x10 100 + #define MPU3050_PWR_MGM_STBY_XG 0x20 101 + #define MPU3050_PWR_MGM_SLEEP 0x40 102 + #define MPU3050_PWR_MGM_RESET 0x80 103 + #define MPU3050_PWR_MGM_MASK 0x40 55 104 56 105 struct axis_data { 57 106 s16 x; ··· 252 203 } 253 204 254 205 /** 206 + * mpu3050_hw_init - initialize hardware 207 + * @sensor: the sensor 208 + * 209 + * Called during device probe; configures the sampling method. 210 + */ 211 + static int __devinit mpu3050_hw_init(struct mpu3050_sensor *sensor) 212 + { 213 + struct i2c_client *client = sensor->client; 214 + int ret; 215 + u8 reg; 216 + 217 + /* Reset */ 218 + ret = i2c_smbus_write_byte_data(client, MPU3050_PWR_MGM, 219 + MPU3050_PWR_MGM_RESET); 220 + if (ret < 0) 221 + return ret; 222 + 223 + ret = i2c_smbus_read_byte_data(client, MPU3050_PWR_MGM); 224 + if (ret < 0) 225 + return ret; 226 + 227 + ret &= ~MPU3050_PWR_MGM_CLKSEL; 228 + ret |= MPU3050_PWR_MGM_PLL_Z; 229 + ret = i2c_smbus_write_byte_data(client, MPU3050_PWR_MGM, ret); 230 + if (ret < 0) 231 + return ret; 232 + 233 + /* Output frequency divider. The poll interval */ 234 + ret = i2c_smbus_write_byte_data(client, MPU3050_SMPLRT_DIV, 235 + MPU3050_DEFAULT_POLL_INTERVAL - 1); 236 + if (ret < 0) 237 + return ret; 238 + 239 + /* Set low pass filter and full scale */ 240 + reg = MPU3050_DEFAULT_FS_RANGE; 241 + reg |= MPU3050_DLPF_CFG_42HZ << 3; 242 + reg |= MPU3050_EXT_SYNC_NONE << 5; 243 + ret = i2c_smbus_write_byte_data(client, MPU3050_DLPF_FS_SYNC, reg); 244 + if (ret < 0) 245 + return ret; 246 + 247 + return 0; 248 + } 249 + 250 + /** 255 251 * mpu3050_probe - device detection callback 256 252 * @client: i2c client of found device 257 253 * @id: id match information ··· 360 266 input_set_drvdata(idev, sensor); 361 267 362 268 pm_runtime_set_active(&client->dev); 269 + 270 + error = mpu3050_hw_init(sensor); 271 + if (error) 272 + goto err_pm_set_suspended; 363 273 364 274 error = request_threaded_irq(client->irq, 365 275 NULL, mpu3050_interrupt_thread,