Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * lis3lv02d.c - ST LIS3LV02DL accelerometer driver |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 Yan Burman |
| 5 | * Copyright (C) 2008 Eric Piel |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 6 | * Copyright (C) 2008-2009 Pavel Machek |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/dmi.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/interrupt.h> |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 30 | #include <linux/input-polldev.h> |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 31 | #include <linux/delay.h> |
| 32 | #include <linux/wait.h> |
| 33 | #include <linux/poll.h> |
Samu Onkalo | f9deb41 | 2010-10-22 07:57:24 -0400 | [diff] [blame] | 34 | #include <linux/slab.h> |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 35 | #include <linux/freezer.h> |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 36 | #include <linux/uaccess.h> |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 37 | #include <linux/miscdevice.h> |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 38 | #include <linux/pm_runtime.h> |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 39 | #include <asm/atomic.h> |
| 40 | #include "lis3lv02d.h" |
| 41 | |
| 42 | #define DRIVER_NAME "lis3lv02d" |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 43 | |
| 44 | /* joystick device poll interval in milliseconds */ |
| 45 | #define MDPS_POLL_INTERVAL 50 |
Samu Onkalo | 4a70a41 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 46 | #define MDPS_POLL_MIN 0 |
| 47 | #define MDPS_POLL_MAX 2000 |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 48 | |
| 49 | #define LIS3_SYSFS_POWERDOWN_DELAY 5000 /* In milliseconds */ |
| 50 | |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 51 | /* |
| 52 | * The sensor can also generate interrupts (DRDY) but it's pretty pointless |
Éric Piel | bc62c14 | 2009-12-14 18:01:39 -0800 | [diff] [blame] | 53 | * because they are generated even if the data do not change. So it's better |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 54 | * to keep the interrupt for the free-fall event. The values are updated at |
| 55 | * 40Hz (at the lowest frequency), but as it can be pretty time consuming on |
| 56 | * some low processor, we poll the sensor only at 20Hz... enough for the |
| 57 | * joystick. |
| 58 | */ |
| 59 | |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 60 | #define LIS3_PWRON_DELAY_WAI_12B (5000) |
| 61 | #define LIS3_PWRON_DELAY_WAI_8B (3000) |
| 62 | |
Samu Onkalo | 32496c7 | 2009-12-14 18:01:46 -0800 | [diff] [blame] | 63 | /* |
| 64 | * LIS3LV02D spec says 1024 LSBs corresponds 1 G -> 1LSB is 1000/1024 mG |
| 65 | * LIS302D spec says: 18 mG / digit |
| 66 | * LIS3_ACCURACY is used to increase accuracy of the intermediate |
| 67 | * calculation results. |
| 68 | */ |
| 69 | #define LIS3_ACCURACY 1024 |
| 70 | /* Sensitivity values for -2G +2G scale */ |
| 71 | #define LIS3_SENSITIVITY_12B ((LIS3_ACCURACY * 1000) / 1024) |
| 72 | #define LIS3_SENSITIVITY_8B (18 * LIS3_ACCURACY) |
| 73 | |
Samu Onkalo | 477bc91 | 2010-10-22 07:57:30 -0400 | [diff] [blame^] | 74 | #define LIS3_DEFAULT_FUZZ_12B 3 |
| 75 | #define LIS3_DEFAULT_FLAT_12B 3 |
| 76 | #define LIS3_DEFAULT_FUZZ_8B 1 |
| 77 | #define LIS3_DEFAULT_FLAT_8B 1 |
Samu Onkalo | 32496c7 | 2009-12-14 18:01:46 -0800 | [diff] [blame] | 78 | |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 79 | struct lis3lv02d lis3_dev = { |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 80 | .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait), |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 83 | EXPORT_SYMBOL_GPL(lis3_dev); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 84 | |
Takashi Iwai | 2ee3214 | 2010-10-01 17:14:25 -0400 | [diff] [blame] | 85 | /* just like param_set_int() but does sanity-check so that it won't point |
| 86 | * over the axis array size |
| 87 | */ |
| 88 | static int param_set_axis(const char *val, const struct kernel_param *kp) |
| 89 | { |
| 90 | int ret = param_set_int(val, kp); |
| 91 | if (!ret) { |
| 92 | int val = *(int *)kp->arg; |
| 93 | if (val < 0) |
| 94 | val = -val; |
| 95 | if (!val || val > 3) |
| 96 | return -EINVAL; |
| 97 | } |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | static struct kernel_param_ops param_ops_axis = { |
| 102 | .set = param_set_axis, |
| 103 | .get = param_get_int, |
| 104 | }; |
| 105 | |
| 106 | module_param_array_named(axes, lis3_dev.ac.as_array, axis, NULL, 0644); |
| 107 | MODULE_PARM_DESC(axes, "Axis-mapping for x,y,z directions"); |
| 108 | |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 109 | static s16 lis3lv02d_read_8(struct lis3lv02d *lis3, int reg) |
| 110 | { |
| 111 | s8 lo; |
| 112 | if (lis3->read(lis3, reg, &lo) < 0) |
| 113 | return 0; |
| 114 | |
| 115 | return lo; |
| 116 | } |
| 117 | |
Éric Piel | bc62c14 | 2009-12-14 18:01:39 -0800 | [diff] [blame] | 118 | static s16 lis3lv02d_read_12(struct lis3lv02d *lis3, int reg) |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 119 | { |
| 120 | u8 lo, hi; |
| 121 | |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 122 | lis3->read(lis3, reg - 1, &lo); |
| 123 | lis3->read(lis3, reg, &hi); |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 124 | /* In "12 bit right justified" mode, bit 6, bit 7, bit 8 = bit 5 */ |
| 125 | return (s16)((hi << 8) | lo); |
| 126 | } |
| 127 | |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 128 | /** |
| 129 | * lis3lv02d_get_axis - For the given axis, give the value converted |
| 130 | * @axis: 1,2,3 - can also be negative |
| 131 | * @hw_values: raw values returned by the hardware |
| 132 | * |
| 133 | * Returns the converted value. |
| 134 | */ |
| 135 | static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3]) |
| 136 | { |
| 137 | if (axis > 0) |
| 138 | return hw_values[axis - 1]; |
| 139 | else |
| 140 | return -hw_values[-axis - 1]; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * lis3lv02d_get_xyz - Get X, Y and Z axis values from the accelerometer |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 145 | * @lis3: pointer to the device struct |
| 146 | * @x: where to store the X axis value |
| 147 | * @y: where to store the Y axis value |
| 148 | * @z: where to store the Z axis value |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 149 | * |
| 150 | * Note that 40Hz input device can eat up about 10% CPU at 800MHZ |
| 151 | */ |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 152 | static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 153 | { |
| 154 | int position[3]; |
Samu Onkalo | 32496c7 | 2009-12-14 18:01:46 -0800 | [diff] [blame] | 155 | int i; |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 156 | |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 157 | position[0] = lis3->read_data(lis3, OUTX); |
| 158 | position[1] = lis3->read_data(lis3, OUTY); |
| 159 | position[2] = lis3->read_data(lis3, OUTZ); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 160 | |
Samu Onkalo | 32496c7 | 2009-12-14 18:01:46 -0800 | [diff] [blame] | 161 | for (i = 0; i < 3; i++) |
| 162 | position[i] = (position[i] * lis3->scale) / LIS3_ACCURACY; |
| 163 | |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 164 | *x = lis3lv02d_get_axis(lis3->ac.x, position); |
| 165 | *y = lis3lv02d_get_axis(lis3->ac.y, position); |
| 166 | *z = lis3lv02d_get_axis(lis3->ac.z, position); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 169 | /* conversion btw sampling rate and the register values */ |
| 170 | static int lis3_12_rates[4] = {40, 160, 640, 2560}; |
| 171 | static int lis3_8_rates[2] = {100, 400}; |
Takashi Iwai | 78537c3 | 2010-09-23 10:01:39 -0700 | [diff] [blame] | 172 | static int lis3_3dc_rates[16] = {0, 1, 10, 25, 50, 100, 200, 400, 1600, 5000}; |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 173 | |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 174 | /* ODR is Output Data Rate */ |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 175 | static int lis3lv02d_get_odr(void) |
| 176 | { |
| 177 | u8 ctrl; |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 178 | int shift; |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 179 | |
| 180 | lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl); |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 181 | ctrl &= lis3_dev.odr_mask; |
| 182 | shift = ffs(lis3_dev.odr_mask) - 1; |
| 183 | return lis3_dev.odrs[(ctrl >> shift)]; |
| 184 | } |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 185 | |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 186 | static int lis3lv02d_set_odr(int rate) |
| 187 | { |
| 188 | u8 ctrl; |
| 189 | int i, len, shift; |
| 190 | |
Takashi Iwai | 78537c3 | 2010-09-23 10:01:39 -0700 | [diff] [blame] | 191 | if (!rate) |
| 192 | return -EINVAL; |
| 193 | |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 194 | lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl); |
| 195 | ctrl &= ~lis3_dev.odr_mask; |
| 196 | len = 1 << hweight_long(lis3_dev.odr_mask); /* # of possible values */ |
| 197 | shift = ffs(lis3_dev.odr_mask) - 1; |
| 198 | |
| 199 | for (i = 0; i < len; i++) |
| 200 | if (lis3_dev.odrs[i] == rate) { |
| 201 | lis3_dev.write(&lis3_dev, CTRL_REG1, |
| 202 | ctrl | (i << shift)); |
| 203 | return 0; |
| 204 | } |
| 205 | return -EINVAL; |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 208 | static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3]) |
| 209 | { |
Takashi Iwai | 78537c3 | 2010-09-23 10:01:39 -0700 | [diff] [blame] | 210 | u8 ctlreg, reg; |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 211 | s16 x, y, z; |
| 212 | u8 selftest; |
| 213 | int ret; |
| 214 | |
| 215 | mutex_lock(&lis3->mutex); |
Takashi Iwai | 78537c3 | 2010-09-23 10:01:39 -0700 | [diff] [blame] | 216 | if (lis3_dev.whoami == WAI_3DC) { |
| 217 | ctlreg = CTRL_REG4; |
| 218 | selftest = CTRL4_ST0; |
| 219 | } else { |
| 220 | ctlreg = CTRL_REG1; |
| 221 | if (lis3_dev.whoami == WAI_12B) |
| 222 | selftest = CTRL1_ST; |
| 223 | else |
| 224 | selftest = CTRL1_STP; |
| 225 | } |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 226 | |
Takashi Iwai | 78537c3 | 2010-09-23 10:01:39 -0700 | [diff] [blame] | 227 | lis3->read(lis3, ctlreg, ®); |
| 228 | lis3->write(lis3, ctlreg, (reg | selftest)); |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 229 | msleep(lis3->pwron_delay / lis3lv02d_get_odr()); |
| 230 | |
| 231 | /* Read directly to avoid axis remap */ |
| 232 | x = lis3->read_data(lis3, OUTX); |
| 233 | y = lis3->read_data(lis3, OUTY); |
| 234 | z = lis3->read_data(lis3, OUTZ); |
| 235 | |
| 236 | /* back to normal settings */ |
Takashi Iwai | 78537c3 | 2010-09-23 10:01:39 -0700 | [diff] [blame] | 237 | lis3->write(lis3, ctlreg, reg); |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 238 | msleep(lis3->pwron_delay / lis3lv02d_get_odr()); |
| 239 | |
| 240 | results[0] = x - lis3->read_data(lis3, OUTX); |
| 241 | results[1] = y - lis3->read_data(lis3, OUTY); |
| 242 | results[2] = z - lis3->read_data(lis3, OUTZ); |
| 243 | |
| 244 | ret = 0; |
| 245 | if (lis3->pdata) { |
| 246 | int i; |
| 247 | for (i = 0; i < 3; i++) { |
| 248 | /* Check against selftest acceptance limits */ |
| 249 | if ((results[i] < lis3->pdata->st_min_limits[i]) || |
| 250 | (results[i] > lis3->pdata->st_max_limits[i])) { |
| 251 | ret = -EIO; |
| 252 | goto fail; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /* test passed */ |
| 258 | fail: |
| 259 | mutex_unlock(&lis3->mutex); |
| 260 | return ret; |
| 261 | } |
| 262 | |
Samu Onkalo | f9deb41 | 2010-10-22 07:57:24 -0400 | [diff] [blame] | 263 | /* |
| 264 | * Order of registers in the list affects to order of the restore process. |
| 265 | * Perhaps it is a good idea to set interrupt enable register as a last one |
| 266 | * after all other configurations |
| 267 | */ |
| 268 | static u8 lis3_wai8_regs[] = { FF_WU_CFG_1, FF_WU_THS_1, FF_WU_DURATION_1, |
| 269 | FF_WU_CFG_2, FF_WU_THS_2, FF_WU_DURATION_2, |
| 270 | CLICK_CFG, CLICK_SRC, CLICK_THSY_X, CLICK_THSZ, |
| 271 | CLICK_TIMELIMIT, CLICK_LATENCY, CLICK_WINDOW, |
| 272 | CTRL_REG1, CTRL_REG2, CTRL_REG3}; |
| 273 | |
| 274 | static u8 lis3_wai12_regs[] = {FF_WU_CFG, FF_WU_THS_L, FF_WU_THS_H, |
| 275 | FF_WU_DURATION, DD_CFG, DD_THSI_L, DD_THSI_H, |
| 276 | DD_THSE_L, DD_THSE_H, |
| 277 | CTRL_REG1, CTRL_REG3, CTRL_REG2}; |
| 278 | |
| 279 | static inline void lis3_context_save(struct lis3lv02d *lis3) |
| 280 | { |
| 281 | int i; |
| 282 | for (i = 0; i < lis3->regs_size; i++) |
| 283 | lis3->read(lis3, lis3->regs[i], &lis3->reg_cache[i]); |
| 284 | lis3->regs_stored = true; |
| 285 | } |
| 286 | |
| 287 | static inline void lis3_context_restore(struct lis3lv02d *lis3) |
| 288 | { |
| 289 | int i; |
| 290 | if (lis3->regs_stored) |
| 291 | for (i = 0; i < lis3->regs_size; i++) |
| 292 | lis3->write(lis3, lis3->regs[i], lis3->reg_cache[i]); |
| 293 | } |
| 294 | |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 295 | void lis3lv02d_poweroff(struct lis3lv02d *lis3) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 296 | { |
Samu Onkalo | f9deb41 | 2010-10-22 07:57:24 -0400 | [diff] [blame] | 297 | if (lis3->reg_ctrl) |
| 298 | lis3_context_save(lis3); |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 299 | /* disable X,Y,Z axis and power down */ |
| 300 | lis3->write(lis3, CTRL_REG1, 0x00); |
Samu Onkalo | f9deb41 | 2010-10-22 07:57:24 -0400 | [diff] [blame] | 301 | if (lis3->reg_ctrl) |
| 302 | lis3->reg_ctrl(lis3, LIS3_REG_OFF); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 303 | } |
Eric Piel | cfce41a | 2009-01-09 16:41:01 -0800 | [diff] [blame] | 304 | EXPORT_SYMBOL_GPL(lis3lv02d_poweroff); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 305 | |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 306 | void lis3lv02d_poweron(struct lis3lv02d *lis3) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 307 | { |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 308 | u8 reg; |
| 309 | |
| 310 | lis3->init(lis3); |
| 311 | |
| 312 | /* |
| 313 | * Common configuration |
Éric Piel | 4b5d95b | 2009-12-14 18:01:40 -0800 | [diff] [blame] | 314 | * BDU: (12 bits sensors only) LSB and MSB values are not updated until |
| 315 | * both have been read. So the value read will always be correct. |
Samu Onkalo | 2a7fade | 2010-10-22 07:57:27 -0400 | [diff] [blame] | 316 | * Set BOOT bit to refresh factory tuning values. |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 317 | */ |
Samu Onkalo | 2a7fade | 2010-10-22 07:57:27 -0400 | [diff] [blame] | 318 | lis3->read(lis3, CTRL_REG2, ®); |
| 319 | if (lis3->whoami == WAI_12B) |
| 320 | reg |= CTRL2_BDU | CTRL2_BOOT; |
| 321 | else |
| 322 | reg |= CTRL2_BOOT_8B; |
| 323 | lis3->write(lis3, CTRL_REG2, reg); |
| 324 | |
| 325 | /* LIS3 power on delay is quite long */ |
| 326 | msleep(lis3->pwron_delay / lis3lv02d_get_odr()); |
| 327 | |
Samu Onkalo | f9deb41 | 2010-10-22 07:57:24 -0400 | [diff] [blame] | 328 | if (lis3->reg_ctrl) |
| 329 | lis3_context_restore(lis3); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 330 | } |
Eric Piel | cfce41a | 2009-01-09 16:41:01 -0800 | [diff] [blame] | 331 | EXPORT_SYMBOL_GPL(lis3lv02d_poweron); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 332 | |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 333 | |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 334 | static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev) |
| 335 | { |
| 336 | int x, y, z; |
| 337 | |
| 338 | mutex_lock(&lis3_dev.mutex); |
| 339 | lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); |
| 340 | input_report_abs(pidev->input, ABS_X, x); |
| 341 | input_report_abs(pidev->input, ABS_Y, y); |
| 342 | input_report_abs(pidev->input, ABS_Z, z); |
| 343 | input_sync(pidev->input); |
| 344 | mutex_unlock(&lis3_dev.mutex); |
| 345 | } |
| 346 | |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 347 | static void lis3lv02d_joystick_open(struct input_polled_dev *pidev) |
| 348 | { |
| 349 | if (lis3_dev.pm_dev) |
| 350 | pm_runtime_get_sync(lis3_dev.pm_dev); |
Samu Onkalo | e726111 | 2010-10-22 07:57:25 -0400 | [diff] [blame] | 351 | |
| 352 | if (lis3_dev.pdata && lis3_dev.whoami == WAI_8B && lis3_dev.idev) |
| 353 | atomic_set(&lis3_dev.wake_thread, 1); |
Samu Onkalo | 821f664 | 2010-10-22 07:57:26 -0400 | [diff] [blame] | 354 | /* |
| 355 | * Update coordinates for the case where poll interval is 0 and |
| 356 | * the chip in running purely under interrupt control |
| 357 | */ |
| 358 | lis3lv02d_joystick_poll(pidev); |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static void lis3lv02d_joystick_close(struct input_polled_dev *pidev) |
| 362 | { |
Samu Onkalo | e726111 | 2010-10-22 07:57:25 -0400 | [diff] [blame] | 363 | atomic_set(&lis3_dev.wake_thread, 0); |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 364 | if (lis3_dev.pm_dev) |
| 365 | pm_runtime_put(lis3_dev.pm_dev); |
| 366 | } |
| 367 | |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 368 | static irqreturn_t lis302dl_interrupt(int irq, void *dummy) |
| 369 | { |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 370 | if (!test_bit(0, &lis3_dev.misc_opened)) |
| 371 | goto out; |
| 372 | |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 373 | /* |
| 374 | * Be careful: on some HP laptops the bios force DD when on battery and |
| 375 | * the lid is closed. This leads to interrupts as soon as a little move |
| 376 | * is done. |
| 377 | */ |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 378 | atomic_inc(&lis3_dev.count); |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 379 | |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 380 | wake_up_interruptible(&lis3_dev.misc_wait); |
| 381 | kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN); |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 382 | out: |
Samu Onkalo | e726111 | 2010-10-22 07:57:25 -0400 | [diff] [blame] | 383 | if (atomic_read(&lis3_dev.wake_thread)) |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 384 | return IRQ_WAKE_THREAD; |
| 385 | return IRQ_HANDLED; |
| 386 | } |
| 387 | |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 388 | static void lis302dl_interrupt_handle_click(struct lis3lv02d *lis3) |
| 389 | { |
| 390 | struct input_dev *dev = lis3->idev->input; |
| 391 | u8 click_src; |
| 392 | |
| 393 | mutex_lock(&lis3->mutex); |
| 394 | lis3->read(lis3, CLICK_SRC, &click_src); |
| 395 | |
| 396 | if (click_src & CLICK_SINGLE_X) { |
| 397 | input_report_key(dev, lis3->mapped_btns[0], 1); |
| 398 | input_report_key(dev, lis3->mapped_btns[0], 0); |
| 399 | } |
| 400 | |
| 401 | if (click_src & CLICK_SINGLE_Y) { |
| 402 | input_report_key(dev, lis3->mapped_btns[1], 1); |
| 403 | input_report_key(dev, lis3->mapped_btns[1], 0); |
| 404 | } |
| 405 | |
| 406 | if (click_src & CLICK_SINGLE_Z) { |
| 407 | input_report_key(dev, lis3->mapped_btns[2], 1); |
| 408 | input_report_key(dev, lis3->mapped_btns[2], 0); |
| 409 | } |
| 410 | input_sync(dev); |
| 411 | mutex_unlock(&lis3->mutex); |
| 412 | } |
| 413 | |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 414 | static irqreturn_t lis302dl_interrupt_thread1_8b(int irq, void *data) |
| 415 | { |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 416 | |
| 417 | struct lis3lv02d *lis3 = data; |
| 418 | |
Samu Onkalo | e726111 | 2010-10-22 07:57:25 -0400 | [diff] [blame] | 419 | if ((lis3->irq_cfg & LIS3_IRQ1_MASK) == LIS3_IRQ1_CLICK) |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 420 | lis302dl_interrupt_handle_click(lis3); |
| 421 | else |
Samu Onkalo | e726111 | 2010-10-22 07:57:25 -0400 | [diff] [blame] | 422 | lis3lv02d_joystick_poll(lis3->idev); |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 423 | |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 424 | return IRQ_HANDLED; |
| 425 | } |
| 426 | |
| 427 | static irqreturn_t lis302dl_interrupt_thread2_8b(int irq, void *data) |
| 428 | { |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 429 | |
| 430 | struct lis3lv02d *lis3 = data; |
| 431 | |
Samu Onkalo | e726111 | 2010-10-22 07:57:25 -0400 | [diff] [blame] | 432 | if ((lis3->irq_cfg & LIS3_IRQ2_MASK) == LIS3_IRQ2_CLICK) |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 433 | lis302dl_interrupt_handle_click(lis3); |
| 434 | else |
Samu Onkalo | e726111 | 2010-10-22 07:57:25 -0400 | [diff] [blame] | 435 | lis3lv02d_joystick_poll(lis3->idev); |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 436 | |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 437 | return IRQ_HANDLED; |
| 438 | } |
| 439 | |
| 440 | static int lis3lv02d_misc_open(struct inode *inode, struct file *file) |
| 441 | { |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 442 | if (test_and_set_bit(0, &lis3_dev.misc_opened)) |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 443 | return -EBUSY; /* already open */ |
| 444 | |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 445 | if (lis3_dev.pm_dev) |
| 446 | pm_runtime_get_sync(lis3_dev.pm_dev); |
| 447 | |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 448 | atomic_set(&lis3_dev.count, 0); |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static int lis3lv02d_misc_release(struct inode *inode, struct file *file) |
| 453 | { |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 454 | fasync_helper(-1, file, 0, &lis3_dev.async_queue); |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 455 | clear_bit(0, &lis3_dev.misc_opened); /* release the device */ |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 456 | if (lis3_dev.pm_dev) |
| 457 | pm_runtime_put(lis3_dev.pm_dev); |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf, |
| 462 | size_t count, loff_t *pos) |
| 463 | { |
| 464 | DECLARE_WAITQUEUE(wait, current); |
| 465 | u32 data; |
| 466 | unsigned char byte_data; |
| 467 | ssize_t retval = 1; |
| 468 | |
| 469 | if (count < 1) |
| 470 | return -EINVAL; |
| 471 | |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 472 | add_wait_queue(&lis3_dev.misc_wait, &wait); |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 473 | while (true) { |
| 474 | set_current_state(TASK_INTERRUPTIBLE); |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 475 | data = atomic_xchg(&lis3_dev.count, 0); |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 476 | if (data) |
| 477 | break; |
| 478 | |
| 479 | if (file->f_flags & O_NONBLOCK) { |
| 480 | retval = -EAGAIN; |
| 481 | goto out; |
| 482 | } |
| 483 | |
| 484 | if (signal_pending(current)) { |
| 485 | retval = -ERESTARTSYS; |
| 486 | goto out; |
| 487 | } |
| 488 | |
| 489 | schedule(); |
| 490 | } |
| 491 | |
| 492 | if (data < 255) |
| 493 | byte_data = data; |
| 494 | else |
| 495 | byte_data = 255; |
| 496 | |
| 497 | /* make sure we are not going into copy_to_user() with |
| 498 | * TASK_INTERRUPTIBLE state */ |
| 499 | set_current_state(TASK_RUNNING); |
| 500 | if (copy_to_user(buf, &byte_data, sizeof(byte_data))) |
| 501 | retval = -EFAULT; |
| 502 | |
| 503 | out: |
| 504 | __set_current_state(TASK_RUNNING); |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 505 | remove_wait_queue(&lis3_dev.misc_wait, &wait); |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 506 | |
| 507 | return retval; |
| 508 | } |
| 509 | |
| 510 | static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait) |
| 511 | { |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 512 | poll_wait(file, &lis3_dev.misc_wait, wait); |
| 513 | if (atomic_read(&lis3_dev.count)) |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 514 | return POLLIN | POLLRDNORM; |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static int lis3lv02d_misc_fasync(int fd, struct file *file, int on) |
| 519 | { |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 520 | return fasync_helper(fd, file, on, &lis3_dev.async_queue); |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static const struct file_operations lis3lv02d_misc_fops = { |
| 524 | .owner = THIS_MODULE, |
| 525 | .llseek = no_llseek, |
| 526 | .read = lis3lv02d_misc_read, |
| 527 | .open = lis3lv02d_misc_open, |
| 528 | .release = lis3lv02d_misc_release, |
| 529 | .poll = lis3lv02d_misc_poll, |
| 530 | .fasync = lis3lv02d_misc_fasync, |
| 531 | }; |
| 532 | |
| 533 | static struct miscdevice lis3lv02d_misc_device = { |
| 534 | .minor = MISC_DYNAMIC_MINOR, |
| 535 | .name = "freefall", |
| 536 | .fops = &lis3lv02d_misc_fops, |
| 537 | }; |
| 538 | |
Eric Piel | cfce41a | 2009-01-09 16:41:01 -0800 | [diff] [blame] | 539 | int lis3lv02d_joystick_enable(void) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 540 | { |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 541 | struct input_dev *input_dev; |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 542 | int err; |
Samu Onkalo | 32496c7 | 2009-12-14 18:01:46 -0800 | [diff] [blame] | 543 | int max_val, fuzz, flat; |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 544 | int btns[] = {BTN_X, BTN_Y, BTN_Z}; |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 545 | |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 546 | if (lis3_dev.idev) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 547 | return -EINVAL; |
| 548 | |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 549 | lis3_dev.idev = input_allocate_polled_device(); |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 550 | if (!lis3_dev.idev) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 551 | return -ENOMEM; |
| 552 | |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 553 | lis3_dev.idev->poll = lis3lv02d_joystick_poll; |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 554 | lis3_dev.idev->open = lis3lv02d_joystick_open; |
| 555 | lis3_dev.idev->close = lis3lv02d_joystick_close; |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 556 | lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL; |
Samu Onkalo | 4a70a41 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 557 | lis3_dev.idev->poll_interval_min = MDPS_POLL_MIN; |
| 558 | lis3_dev.idev->poll_interval_max = MDPS_POLL_MAX; |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 559 | input_dev = lis3_dev.idev->input; |
| 560 | |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 561 | input_dev->name = "ST LIS3LV02DL Accelerometer"; |
| 562 | input_dev->phys = DRIVER_NAME "/input0"; |
| 563 | input_dev->id.bustype = BUS_HOST; |
| 564 | input_dev->id.vendor = 0; |
| 565 | input_dev->dev.parent = &lis3_dev.pdev->dev; |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 566 | |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 567 | set_bit(EV_ABS, input_dev->evbit); |
Samu Onkalo | 32496c7 | 2009-12-14 18:01:46 -0800 | [diff] [blame] | 568 | max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY; |
Samu Onkalo | 477bc91 | 2010-10-22 07:57:30 -0400 | [diff] [blame^] | 569 | if (lis3_dev.whoami == WAI_12B) { |
| 570 | fuzz = LIS3_DEFAULT_FUZZ_12B; |
| 571 | flat = LIS3_DEFAULT_FLAT_12B; |
| 572 | } else { |
| 573 | fuzz = LIS3_DEFAULT_FUZZ_8B; |
| 574 | flat = LIS3_DEFAULT_FLAT_8B; |
| 575 | } |
| 576 | fuzz = (fuzz * lis3_dev.scale) / LIS3_ACCURACY; |
| 577 | flat = (flat * lis3_dev.scale) / LIS3_ACCURACY; |
| 578 | |
Samu Onkalo | 32496c7 | 2009-12-14 18:01:46 -0800 | [diff] [blame] | 579 | input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat); |
| 580 | input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat); |
| 581 | input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 582 | |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 583 | lis3_dev.mapped_btns[0] = lis3lv02d_get_axis(abs(lis3_dev.ac.x), btns); |
| 584 | lis3_dev.mapped_btns[1] = lis3lv02d_get_axis(abs(lis3_dev.ac.y), btns); |
| 585 | lis3_dev.mapped_btns[2] = lis3lv02d_get_axis(abs(lis3_dev.ac.z), btns); |
| 586 | |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 587 | err = input_register_polled_device(lis3_dev.idev); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 588 | if (err) { |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 589 | input_free_polled_device(lis3_dev.idev); |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 590 | lis3_dev.idev = NULL; |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | return err; |
| 594 | } |
Eric Piel | cfce41a | 2009-01-09 16:41:01 -0800 | [diff] [blame] | 595 | EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 596 | |
Eric Piel | cfce41a | 2009-01-09 16:41:01 -0800 | [diff] [blame] | 597 | void lis3lv02d_joystick_disable(void) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 598 | { |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 599 | if (lis3_dev.irq) |
| 600 | free_irq(lis3_dev.irq, &lis3_dev); |
| 601 | if (lis3_dev.pdata && lis3_dev.pdata->irq2) |
| 602 | free_irq(lis3_dev.pdata->irq2, &lis3_dev); |
| 603 | |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 604 | if (!lis3_dev.idev) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 605 | return; |
| 606 | |
Eric Piel | c288424 | 2009-06-16 15:34:13 -0700 | [diff] [blame] | 607 | if (lis3_dev.irq) |
| 608 | misc_deregister(&lis3lv02d_misc_device); |
Eric Piel | dc6ea97 | 2009-06-16 15:34:15 -0700 | [diff] [blame] | 609 | input_unregister_polled_device(lis3_dev.idev); |
Samu Onkalo | 66c8569 | 2009-12-14 18:01:39 -0800 | [diff] [blame] | 610 | input_free_polled_device(lis3_dev.idev); |
Pavel Machek | be84cfc | 2009-03-31 15:24:26 -0700 | [diff] [blame] | 611 | lis3_dev.idev = NULL; |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 612 | } |
Eric Piel | cfce41a | 2009-01-09 16:41:01 -0800 | [diff] [blame] | 613 | EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 614 | |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 615 | /* Sysfs stuff */ |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 616 | static void lis3lv02d_sysfs_poweron(struct lis3lv02d *lis3) |
| 617 | { |
| 618 | /* |
| 619 | * SYSFS functions are fast visitors so put-call |
| 620 | * immediately after the get-call. However, keep |
| 621 | * chip running for a while and schedule delayed |
| 622 | * suspend. This way periodic sysfs calls doesn't |
| 623 | * suffer from relatively long power up time. |
| 624 | */ |
| 625 | |
| 626 | if (lis3->pm_dev) { |
| 627 | pm_runtime_get_sync(lis3->pm_dev); |
| 628 | pm_runtime_put_noidle(lis3->pm_dev); |
| 629 | pm_schedule_suspend(lis3->pm_dev, LIS3_SYSFS_POWERDOWN_DELAY); |
| 630 | } |
| 631 | } |
| 632 | |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 633 | static ssize_t lis3lv02d_selftest_show(struct device *dev, |
| 634 | struct device_attribute *attr, char *buf) |
| 635 | { |
| 636 | int result; |
| 637 | s16 values[3]; |
| 638 | |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 639 | lis3lv02d_sysfs_poweron(&lis3_dev); |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 640 | result = lis3lv02d_selftest(&lis3_dev, values); |
| 641 | return sprintf(buf, "%s %d %d %d\n", result == 0 ? "OK" : "FAIL", |
| 642 | values[0], values[1], values[2]); |
| 643 | } |
| 644 | |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 645 | static ssize_t lis3lv02d_position_show(struct device *dev, |
| 646 | struct device_attribute *attr, char *buf) |
| 647 | { |
| 648 | int x, y, z; |
| 649 | |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 650 | lis3lv02d_sysfs_poweron(&lis3_dev); |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 651 | mutex_lock(&lis3_dev.mutex); |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 652 | lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 653 | mutex_unlock(&lis3_dev.mutex); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 654 | return sprintf(buf, "(%d,%d,%d)\n", x, y, z); |
| 655 | } |
| 656 | |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 657 | static ssize_t lis3lv02d_rate_show(struct device *dev, |
| 658 | struct device_attribute *attr, char *buf) |
| 659 | { |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 660 | lis3lv02d_sysfs_poweron(&lis3_dev); |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 661 | return sprintf(buf, "%d\n", lis3lv02d_get_odr()); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 662 | } |
| 663 | |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 664 | static ssize_t lis3lv02d_rate_set(struct device *dev, |
| 665 | struct device_attribute *attr, const char *buf, |
| 666 | size_t count) |
| 667 | { |
| 668 | unsigned long rate; |
| 669 | |
| 670 | if (strict_strtoul(buf, 0, &rate)) |
| 671 | return -EINVAL; |
| 672 | |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 673 | lis3lv02d_sysfs_poweron(&lis3_dev); |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 674 | if (lis3lv02d_set_odr(rate)) |
| 675 | return -EINVAL; |
| 676 | |
| 677 | return count; |
| 678 | } |
| 679 | |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 680 | static DEVICE_ATTR(selftest, S_IRUSR, lis3lv02d_selftest_show, NULL); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 681 | static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL); |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 682 | static DEVICE_ATTR(rate, S_IRUGO | S_IWUSR, lis3lv02d_rate_show, |
| 683 | lis3lv02d_rate_set); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 684 | |
| 685 | static struct attribute *lis3lv02d_attributes[] = { |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 686 | &dev_attr_selftest.attr, |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 687 | &dev_attr_position.attr, |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 688 | &dev_attr_rate.attr, |
| 689 | NULL |
| 690 | }; |
| 691 | |
| 692 | static struct attribute_group lis3lv02d_attribute_group = { |
| 693 | .attrs = lis3lv02d_attributes |
| 694 | }; |
| 695 | |
Eric Piel | cfce41a | 2009-01-09 16:41:01 -0800 | [diff] [blame] | 696 | |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 697 | static int lis3lv02d_add_fs(struct lis3lv02d *lis3) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 698 | { |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 699 | lis3->pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); |
| 700 | if (IS_ERR(lis3->pdev)) |
| 701 | return PTR_ERR(lis3->pdev); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 702 | |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 703 | return sysfs_create_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 704 | } |
| 705 | |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 706 | int lis3lv02d_remove_fs(struct lis3lv02d *lis3) |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 707 | { |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 708 | sysfs_remove_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group); |
| 709 | platform_device_unregister(lis3->pdev); |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 710 | if (lis3->pm_dev) { |
| 711 | /* Barrier after the sysfs remove */ |
| 712 | pm_runtime_barrier(lis3->pm_dev); |
| 713 | |
| 714 | /* SYSFS may have left chip running. Turn off if necessary */ |
| 715 | if (!pm_runtime_suspended(lis3->pm_dev)) |
| 716 | lis3lv02d_poweroff(&lis3_dev); |
| 717 | |
| 718 | pm_runtime_disable(lis3->pm_dev); |
| 719 | pm_runtime_set_suspended(lis3->pm_dev); |
| 720 | } |
Samu Onkalo | f9deb41 | 2010-10-22 07:57:24 -0400 | [diff] [blame] | 721 | kfree(lis3->reg_cache); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 722 | return 0; |
| 723 | } |
Eric Piel | cfce41a | 2009-01-09 16:41:01 -0800 | [diff] [blame] | 724 | EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 725 | |
Samu Onkalo | ecc437a | 2010-05-24 14:33:34 -0700 | [diff] [blame] | 726 | static void lis3lv02d_8b_configure(struct lis3lv02d *dev, |
| 727 | struct lis3lv02d_platform_data *p) |
| 728 | { |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 729 | int err; |
Samu Onkalo | 342c5f1 | 2010-05-24 14:33:35 -0700 | [diff] [blame] | 730 | int ctrl2 = p->hipass_ctrl; |
| 731 | |
Samu Onkalo | ecc437a | 2010-05-24 14:33:34 -0700 | [diff] [blame] | 732 | if (p->click_flags) { |
| 733 | dev->write(dev, CLICK_CFG, p->click_flags); |
| 734 | dev->write(dev, CLICK_TIMELIMIT, p->click_time_limit); |
| 735 | dev->write(dev, CLICK_LATENCY, p->click_latency); |
| 736 | dev->write(dev, CLICK_WINDOW, p->click_window); |
| 737 | dev->write(dev, CLICK_THSZ, p->click_thresh_z & 0xf); |
| 738 | dev->write(dev, CLICK_THSY_X, |
| 739 | (p->click_thresh_x & 0xf) | |
| 740 | (p->click_thresh_y << 4)); |
Samu Onkalo | 6d94d40 | 2010-05-24 14:33:37 -0700 | [diff] [blame] | 741 | |
| 742 | if (dev->idev) { |
| 743 | struct input_dev *input_dev = lis3_dev.idev->input; |
| 744 | input_set_capability(input_dev, EV_KEY, BTN_X); |
| 745 | input_set_capability(input_dev, EV_KEY, BTN_Y); |
| 746 | input_set_capability(input_dev, EV_KEY, BTN_Z); |
| 747 | } |
Samu Onkalo | ecc437a | 2010-05-24 14:33:34 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | if (p->wakeup_flags) { |
| 751 | dev->write(dev, FF_WU_CFG_1, p->wakeup_flags); |
| 752 | dev->write(dev, FF_WU_THS_1, p->wakeup_thresh & 0x7f); |
Samu Onkalo | cc23aa1 | 2010-10-22 07:57:29 -0400 | [diff] [blame] | 753 | /* pdata value + 1 to keep this backward compatible*/ |
| 754 | dev->write(dev, FF_WU_DURATION_1, p->duration1 + 1); |
Samu Onkalo | 342c5f1 | 2010-05-24 14:33:35 -0700 | [diff] [blame] | 755 | ctrl2 ^= HP_FF_WU1; /* Xor to keep compatible with old pdata*/ |
Samu Onkalo | ecc437a | 2010-05-24 14:33:34 -0700 | [diff] [blame] | 756 | } |
Samu Onkalo | 342c5f1 | 2010-05-24 14:33:35 -0700 | [diff] [blame] | 757 | |
| 758 | if (p->wakeup_flags2) { |
| 759 | dev->write(dev, FF_WU_CFG_2, p->wakeup_flags2); |
| 760 | dev->write(dev, FF_WU_THS_2, p->wakeup_thresh2 & 0x7f); |
Samu Onkalo | cc23aa1 | 2010-10-22 07:57:29 -0400 | [diff] [blame] | 761 | /* pdata value + 1 to keep this backward compatible*/ |
| 762 | dev->write(dev, FF_WU_DURATION_2, p->duration2 + 1); |
Samu Onkalo | 342c5f1 | 2010-05-24 14:33:35 -0700 | [diff] [blame] | 763 | ctrl2 ^= HP_FF_WU2; /* Xor to keep compatible with old pdata*/ |
| 764 | } |
| 765 | /* Configure hipass filters */ |
| 766 | dev->write(dev, CTRL_REG2, ctrl2); |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 767 | |
| 768 | if (p->irq2) { |
| 769 | err = request_threaded_irq(p->irq2, |
| 770 | NULL, |
| 771 | lis302dl_interrupt_thread2_8b, |
Samu Onkalo | cc23aa1 | 2010-10-22 07:57:29 -0400 | [diff] [blame] | 772 | IRQF_TRIGGER_RISING | IRQF_ONESHOT | |
| 773 | (p->irq_flags2 & IRQF_TRIGGER_MASK), |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 774 | DRIVER_NAME, &lis3_dev); |
| 775 | if (err < 0) |
| 776 | printk(KERN_ERR DRIVER_NAME |
| 777 | "No second IRQ. Limited functionality\n"); |
| 778 | } |
Samu Onkalo | ecc437a | 2010-05-24 14:33:34 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Daniel Mack | ab337a6 | 2009-03-31 15:24:31 -0700 | [diff] [blame] | 781 | /* |
| 782 | * Initialise the accelerometer and the various subsystems. |
Éric Piel | bc62c14 | 2009-12-14 18:01:39 -0800 | [diff] [blame] | 783 | * Should be rather independent of the bus system. |
Daniel Mack | ab337a6 | 2009-03-31 15:24:31 -0700 | [diff] [blame] | 784 | */ |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 785 | int lis3lv02d_init_device(struct lis3lv02d *dev) |
Daniel Mack | ab337a6 | 2009-03-31 15:24:31 -0700 | [diff] [blame] | 786 | { |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 787 | int err; |
| 788 | irq_handler_t thread_fn; |
Samu Onkalo | cc23aa1 | 2010-10-22 07:57:29 -0400 | [diff] [blame] | 789 | int irq_flags = 0; |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 790 | |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 791 | dev->whoami = lis3lv02d_read_8(dev, WHO_AM_I); |
| 792 | |
| 793 | switch (dev->whoami) { |
Éric Piel | bc62c14 | 2009-12-14 18:01:39 -0800 | [diff] [blame] | 794 | case WAI_12B: |
| 795 | printk(KERN_INFO DRIVER_NAME ": 12 bits sensor found\n"); |
| 796 | dev->read_data = lis3lv02d_read_12; |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 797 | dev->mdps_max_val = 2048; |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 798 | dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B; |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 799 | dev->odrs = lis3_12_rates; |
| 800 | dev->odr_mask = CTRL1_DF0 | CTRL1_DF1; |
Samu Onkalo | 32496c7 | 2009-12-14 18:01:46 -0800 | [diff] [blame] | 801 | dev->scale = LIS3_SENSITIVITY_12B; |
Samu Onkalo | f9deb41 | 2010-10-22 07:57:24 -0400 | [diff] [blame] | 802 | dev->regs = lis3_wai12_regs; |
| 803 | dev->regs_size = ARRAY_SIZE(lis3_wai12_regs); |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 804 | break; |
Éric Piel | bc62c14 | 2009-12-14 18:01:39 -0800 | [diff] [blame] | 805 | case WAI_8B: |
| 806 | printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n"); |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 807 | dev->read_data = lis3lv02d_read_8; |
| 808 | dev->mdps_max_val = 128; |
Samu Onkalo | 641615a | 2009-12-14 18:01:41 -0800 | [diff] [blame] | 809 | dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; |
Samu Onkalo | a253aae | 2009-12-14 18:01:44 -0800 | [diff] [blame] | 810 | dev->odrs = lis3_8_rates; |
| 811 | dev->odr_mask = CTRL1_DR; |
Samu Onkalo | 32496c7 | 2009-12-14 18:01:46 -0800 | [diff] [blame] | 812 | dev->scale = LIS3_SENSITIVITY_8B; |
Samu Onkalo | f9deb41 | 2010-10-22 07:57:24 -0400 | [diff] [blame] | 813 | dev->regs = lis3_wai8_regs; |
| 814 | dev->regs_size = ARRAY_SIZE(lis3_wai8_regs); |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 815 | break; |
Takashi Iwai | 78537c3 | 2010-09-23 10:01:39 -0700 | [diff] [blame] | 816 | case WAI_3DC: |
| 817 | printk(KERN_INFO DRIVER_NAME ": 8 bits 3DC sensor found\n"); |
| 818 | dev->read_data = lis3lv02d_read_8; |
| 819 | dev->mdps_max_val = 128; |
| 820 | dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; |
| 821 | dev->odrs = lis3_3dc_rates; |
| 822 | dev->odr_mask = CTRL1_ODR0|CTRL1_ODR1|CTRL1_ODR2|CTRL1_ODR3; |
| 823 | dev->scale = LIS3_SENSITIVITY_8B; |
| 824 | break; |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 825 | default: |
| 826 | printk(KERN_ERR DRIVER_NAME |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 827 | ": unknown sensor type 0x%X\n", dev->whoami); |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 828 | return -EINVAL; |
| 829 | } |
| 830 | |
Samu Onkalo | f9deb41 | 2010-10-22 07:57:24 -0400 | [diff] [blame] | 831 | dev->reg_cache = kzalloc(max(sizeof(lis3_wai8_regs), |
| 832 | sizeof(lis3_wai12_regs)), GFP_KERNEL); |
| 833 | |
| 834 | if (dev->reg_cache == NULL) { |
| 835 | printk(KERN_ERR DRIVER_NAME "out of memory\n"); |
| 836 | return -ENOMEM; |
| 837 | } |
| 838 | |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 839 | mutex_init(&dev->mutex); |
Samu Onkalo | e726111 | 2010-10-22 07:57:25 -0400 | [diff] [blame] | 840 | atomic_set(&dev->wake_thread, 0); |
Samu Onkalo | 2db4a76 | 2009-12-14 18:01:43 -0800 | [diff] [blame] | 841 | |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 842 | lis3lv02d_add_fs(dev); |
Eric Piel | a002ee8 | 2009-06-16 15:34:14 -0700 | [diff] [blame] | 843 | lis3lv02d_poweron(dev); |
Daniel Mack | ab337a6 | 2009-03-31 15:24:31 -0700 | [diff] [blame] | 844 | |
Samu Onkalo | 2a34699 | 2010-10-22 07:57:23 -0400 | [diff] [blame] | 845 | if (dev->pm_dev) { |
| 846 | pm_runtime_set_active(dev->pm_dev); |
| 847 | pm_runtime_enable(dev->pm_dev); |
| 848 | } |
| 849 | |
Daniel Mack | ab337a6 | 2009-03-31 15:24:31 -0700 | [diff] [blame] | 850 | if (lis3lv02d_joystick_enable()) |
| 851 | printk(KERN_ERR DRIVER_NAME ": joystick initialization failed\n"); |
| 852 | |
Daniel Mack | 8f3128e | 2009-06-16 15:34:17 -0700 | [diff] [blame] | 853 | /* passing in platform specific data is purely optional and only |
| 854 | * used by the SPI transport layer at the moment */ |
| 855 | if (dev->pdata) { |
| 856 | struct lis3lv02d_platform_data *p = dev->pdata; |
| 857 | |
Samu Onkalo | ecc437a | 2010-05-24 14:33:34 -0700 | [diff] [blame] | 858 | if (dev->whoami == WAI_8B) |
| 859 | lis3lv02d_8b_configure(dev, p); |
Daniel Mack | 8873c33 | 2009-09-21 17:04:43 -0700 | [diff] [blame] | 860 | |
Samu Onkalo | cc23aa1 | 2010-10-22 07:57:29 -0400 | [diff] [blame] | 861 | irq_flags = p->irq_flags1 & IRQF_TRIGGER_MASK; |
| 862 | |
Samu Onkalo | e726111 | 2010-10-22 07:57:25 -0400 | [diff] [blame] | 863 | dev->irq_cfg = p->irq_cfg; |
Daniel Mack | 8f3128e | 2009-06-16 15:34:17 -0700 | [diff] [blame] | 864 | if (p->irq_cfg) |
| 865 | dev->write(dev, CTRL_REG3, p->irq_cfg); |
Samu Onkalo | cc23aa1 | 2010-10-22 07:57:29 -0400 | [diff] [blame] | 866 | |
| 867 | if (p->default_rate) |
| 868 | lis3lv02d_set_odr(p->default_rate); |
Daniel Mack | 8f3128e | 2009-06-16 15:34:17 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 871 | /* bail if we did not get an IRQ from the bus layer */ |
Daniel Mack | ab337a6 | 2009-03-31 15:24:31 -0700 | [diff] [blame] | 872 | if (!dev->irq) { |
| 873 | printk(KERN_ERR DRIVER_NAME |
Daniel Mack | a38da2e | 2009-03-31 15:24:32 -0700 | [diff] [blame] | 874 | ": No IRQ. Disabling /dev/freefall\n"); |
Daniel Mack | ab337a6 | 2009-03-31 15:24:31 -0700 | [diff] [blame] | 875 | goto out; |
| 876 | } |
| 877 | |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 878 | /* |
| 879 | * The sensor can generate interrupts for free-fall and direction |
| 880 | * detection (distinguishable with FF_WU_SRC and DD_SRC) but to keep |
| 881 | * the things simple and _fast_ we activate it only for free-fall, so |
| 882 | * no need to read register (very slow with ACPI). For the same reason, |
| 883 | * we forbid shared interrupts. |
| 884 | * |
| 885 | * IRQF_TRIGGER_RISING seems pointless on HP laptops because the |
| 886 | * io-apic is not configurable (and generates a warning) but I keep it |
| 887 | * in case of support for other hardware. |
| 888 | */ |
Takashi Iwai | f7c77a3 | 2010-09-23 10:01:11 -0700 | [diff] [blame] | 889 | if (dev->pdata && dev->whoami == WAI_8B) |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 890 | thread_fn = lis302dl_interrupt_thread1_8b; |
| 891 | else |
| 892 | thread_fn = NULL; |
| 893 | |
| 894 | err = request_threaded_irq(dev->irq, lis302dl_interrupt, |
| 895 | thread_fn, |
Samu Onkalo | cc23aa1 | 2010-10-22 07:57:29 -0400 | [diff] [blame] | 896 | IRQF_TRIGGER_RISING | IRQF_ONESHOT | |
| 897 | irq_flags, |
Samu Onkalo | 92ba4fe | 2010-05-24 14:33:36 -0700 | [diff] [blame] | 898 | DRIVER_NAME, &lis3_dev); |
| 899 | |
| 900 | if (err < 0) { |
| 901 | printk(KERN_ERR DRIVER_NAME "Cannot get IRQ\n"); |
| 902 | goto out; |
| 903 | } |
| 904 | |
Daniel Mack | ab337a6 | 2009-03-31 15:24:31 -0700 | [diff] [blame] | 905 | if (misc_register(&lis3lv02d_misc_device)) |
| 906 | printk(KERN_ERR DRIVER_NAME ": misc_register failed\n"); |
| 907 | out: |
Daniel Mack | ab337a6 | 2009-03-31 15:24:31 -0700 | [diff] [blame] | 908 | return 0; |
| 909 | } |
| 910 | EXPORT_SYMBOL_GPL(lis3lv02d_init_device); |
| 911 | |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 912 | MODULE_DESCRIPTION("ST LIS3LV02Dx three-axis digital accelerometer driver"); |
Pavel Machek | ef2cfc7 | 2009-02-18 14:48:23 -0800 | [diff] [blame] | 913 | MODULE_AUTHOR("Yan Burman, Eric Piel, Pavel Machek"); |
Pavel Machek | 455fbdd | 2008-11-12 13:27:02 -0800 | [diff] [blame] | 914 | MODULE_LICENSE("GPL"); |