lis3lv02d.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * lis3lv02d.c - ST LIS3LV02DL accelerometer driver
  3. *
  4. * Copyright (C) 2007-2008 Yan Burman
  5. * Copyright (C) 2008 Eric Piel
  6. * Copyright (C) 2008-2009 Pavel Machek
  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. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/dmi.h>
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/input-polldev.h>
  30. #include <linux/delay.h>
  31. #include <linux/wait.h>
  32. #include <linux/poll.h>
  33. #include <linux/freezer.h>
  34. #include <linux/uaccess.h>
  35. #include <linux/miscdevice.h>
  36. #include <asm/atomic.h>
  37. #include "lis3lv02d.h"
  38. #define DRIVER_NAME "lis3lv02d"
  39. /* joystick device poll interval in milliseconds */
  40. #define MDPS_POLL_INTERVAL 50
  41. /*
  42. * The sensor can also generate interrupts (DRDY) but it's pretty pointless
  43. * because they are generated even if the data do not change. So it's better
  44. * to keep the interrupt for the free-fall event. The values are updated at
  45. * 40Hz (at the lowest frequency), but as it can be pretty time consuming on
  46. * some low processor, we poll the sensor only at 20Hz... enough for the
  47. * joystick.
  48. */
  49. #define LIS3_PWRON_DELAY_WAI_12B (5000)
  50. #define LIS3_PWRON_DELAY_WAI_8B (3000)
  51. /*
  52. * LIS3LV02D spec says 1024 LSBs corresponds 1 G -> 1LSB is 1000/1024 mG
  53. * LIS302D spec says: 18 mG / digit
  54. * LIS3_ACCURACY is used to increase accuracy of the intermediate
  55. * calculation results.
  56. */
  57. #define LIS3_ACCURACY 1024
  58. /* Sensitivity values for -2G +2G scale */
  59. #define LIS3_SENSITIVITY_12B ((LIS3_ACCURACY * 1000) / 1024)
  60. #define LIS3_SENSITIVITY_8B (18 * LIS3_ACCURACY)
  61. #define LIS3_DEFAULT_FUZZ 3
  62. #define LIS3_DEFAULT_FLAT 3
  63. struct lis3lv02d lis3_dev = {
  64. .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait),
  65. };
  66. EXPORT_SYMBOL_GPL(lis3_dev);
  67. static s16 lis3lv02d_read_8(struct lis3lv02d *lis3, int reg)
  68. {
  69. s8 lo;
  70. if (lis3->read(lis3, reg, &lo) < 0)
  71. return 0;
  72. return lo;
  73. }
  74. static s16 lis3lv02d_read_12(struct lis3lv02d *lis3, int reg)
  75. {
  76. u8 lo, hi;
  77. lis3->read(lis3, reg - 1, &lo);
  78. lis3->read(lis3, reg, &hi);
  79. /* In "12 bit right justified" mode, bit 6, bit 7, bit 8 = bit 5 */
  80. return (s16)((hi << 8) | lo);
  81. }
  82. /**
  83. * lis3lv02d_get_axis - For the given axis, give the value converted
  84. * @axis: 1,2,3 - can also be negative
  85. * @hw_values: raw values returned by the hardware
  86. *
  87. * Returns the converted value.
  88. */
  89. static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3])
  90. {
  91. if (axis > 0)
  92. return hw_values[axis - 1];
  93. else
  94. return -hw_values[-axis - 1];
  95. }
  96. /**
  97. * lis3lv02d_get_xyz - Get X, Y and Z axis values from the accelerometer
  98. * @lis3: pointer to the device struct
  99. * @x: where to store the X axis value
  100. * @y: where to store the Y axis value
  101. * @z: where to store the Z axis value
  102. *
  103. * Note that 40Hz input device can eat up about 10% CPU at 800MHZ
  104. */
  105. static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z)
  106. {
  107. int position[3];
  108. int i;
  109. mutex_lock(&lis3->mutex);
  110. position[0] = lis3->read_data(lis3, OUTX);
  111. position[1] = lis3->read_data(lis3, OUTY);
  112. position[2] = lis3->read_data(lis3, OUTZ);
  113. mutex_unlock(&lis3->mutex);
  114. for (i = 0; i < 3; i++)
  115. position[i] = (position[i] * lis3->scale) / LIS3_ACCURACY;
  116. *x = lis3lv02d_get_axis(lis3->ac.x, position);
  117. *y = lis3lv02d_get_axis(lis3->ac.y, position);
  118. *z = lis3lv02d_get_axis(lis3->ac.z, position);
  119. }
  120. /* conversion btw sampling rate and the register values */
  121. static int lis3_12_rates[4] = {40, 160, 640, 2560};
  122. static int lis3_8_rates[2] = {100, 400};
  123. /* ODR is Output Data Rate */
  124. static int lis3lv02d_get_odr(void)
  125. {
  126. u8 ctrl;
  127. int shift;
  128. lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
  129. ctrl &= lis3_dev.odr_mask;
  130. shift = ffs(lis3_dev.odr_mask) - 1;
  131. return lis3_dev.odrs[(ctrl >> shift)];
  132. }
  133. static int lis3lv02d_set_odr(int rate)
  134. {
  135. u8 ctrl;
  136. int i, len, shift;
  137. lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
  138. ctrl &= ~lis3_dev.odr_mask;
  139. len = 1 << hweight_long(lis3_dev.odr_mask); /* # of possible values */
  140. shift = ffs(lis3_dev.odr_mask) - 1;
  141. for (i = 0; i < len; i++)
  142. if (lis3_dev.odrs[i] == rate) {
  143. lis3_dev.write(&lis3_dev, CTRL_REG1,
  144. ctrl | (i << shift));
  145. return 0;
  146. }
  147. return -EINVAL;
  148. }
  149. static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
  150. {
  151. u8 reg;
  152. s16 x, y, z;
  153. u8 selftest;
  154. int ret;
  155. mutex_lock(&lis3->mutex);
  156. if (lis3_dev.whoami == WAI_12B)
  157. selftest = CTRL1_ST;
  158. else
  159. selftest = CTRL1_STP;
  160. lis3->read(lis3, CTRL_REG1, &reg);
  161. lis3->write(lis3, CTRL_REG1, (reg | selftest));
  162. msleep(lis3->pwron_delay / lis3lv02d_get_odr());
  163. /* Read directly to avoid axis remap */
  164. x = lis3->read_data(lis3, OUTX);
  165. y = lis3->read_data(lis3, OUTY);
  166. z = lis3->read_data(lis3, OUTZ);
  167. /* back to normal settings */
  168. lis3->write(lis3, CTRL_REG1, reg);
  169. msleep(lis3->pwron_delay / lis3lv02d_get_odr());
  170. results[0] = x - lis3->read_data(lis3, OUTX);
  171. results[1] = y - lis3->read_data(lis3, OUTY);
  172. results[2] = z - lis3->read_data(lis3, OUTZ);
  173. ret = 0;
  174. if (lis3->pdata) {
  175. int i;
  176. for (i = 0; i < 3; i++) {
  177. /* Check against selftest acceptance limits */
  178. if ((results[i] < lis3->pdata->st_min_limits[i]) ||
  179. (results[i] > lis3->pdata->st_max_limits[i])) {
  180. ret = -EIO;
  181. goto fail;
  182. }
  183. }
  184. }
  185. /* test passed */
  186. fail:
  187. mutex_unlock(&lis3->mutex);
  188. return ret;
  189. }
  190. void lis3lv02d_poweroff(struct lis3lv02d *lis3)
  191. {
  192. /* disable X,Y,Z axis and power down */
  193. lis3->write(lis3, CTRL_REG1, 0x00);
  194. }
  195. EXPORT_SYMBOL_GPL(lis3lv02d_poweroff);
  196. void lis3lv02d_poweron(struct lis3lv02d *lis3)
  197. {
  198. u8 reg;
  199. lis3->init(lis3);
  200. /* LIS3 power on delay is quite long */
  201. msleep(lis3->pwron_delay / lis3lv02d_get_odr());
  202. /*
  203. * Common configuration
  204. * BDU: (12 bits sensors only) LSB and MSB values are not updated until
  205. * both have been read. So the value read will always be correct.
  206. */
  207. if (lis3->whoami == WAI_12B) {
  208. lis3->read(lis3, CTRL_REG2, &reg);
  209. reg |= CTRL2_BDU;
  210. lis3->write(lis3, CTRL_REG2, reg);
  211. }
  212. }
  213. EXPORT_SYMBOL_GPL(lis3lv02d_poweron);
  214. static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
  215. {
  216. /*
  217. * Be careful: on some HP laptops the bios force DD when on battery and
  218. * the lid is closed. This leads to interrupts as soon as a little move
  219. * is done.
  220. */
  221. atomic_inc(&lis3_dev.count);
  222. wake_up_interruptible(&lis3_dev.misc_wait);
  223. kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
  224. return IRQ_HANDLED;
  225. }
  226. static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
  227. {
  228. int ret;
  229. if (test_and_set_bit(0, &lis3_dev.misc_opened))
  230. return -EBUSY; /* already open */
  231. atomic_set(&lis3_dev.count, 0);
  232. /*
  233. * The sensor can generate interrupts for free-fall and direction
  234. * detection (distinguishable with FF_WU_SRC and DD_SRC) but to keep
  235. * the things simple and _fast_ we activate it only for free-fall, so
  236. * no need to read register (very slow with ACPI). For the same reason,
  237. * we forbid shared interrupts.
  238. *
  239. * IRQF_TRIGGER_RISING seems pointless on HP laptops because the
  240. * io-apic is not configurable (and generates a warning) but I keep it
  241. * in case of support for other hardware.
  242. */
  243. ret = request_irq(lis3_dev.irq, lis302dl_interrupt, IRQF_TRIGGER_RISING,
  244. DRIVER_NAME, &lis3_dev);
  245. if (ret) {
  246. clear_bit(0, &lis3_dev.misc_opened);
  247. printk(KERN_ERR DRIVER_NAME ": IRQ%d allocation failed\n", lis3_dev.irq);
  248. return -EBUSY;
  249. }
  250. return 0;
  251. }
  252. static int lis3lv02d_misc_release(struct inode *inode, struct file *file)
  253. {
  254. fasync_helper(-1, file, 0, &lis3_dev.async_queue);
  255. free_irq(lis3_dev.irq, &lis3_dev);
  256. clear_bit(0, &lis3_dev.misc_opened); /* release the device */
  257. return 0;
  258. }
  259. static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
  260. size_t count, loff_t *pos)
  261. {
  262. DECLARE_WAITQUEUE(wait, current);
  263. u32 data;
  264. unsigned char byte_data;
  265. ssize_t retval = 1;
  266. if (count < 1)
  267. return -EINVAL;
  268. add_wait_queue(&lis3_dev.misc_wait, &wait);
  269. while (true) {
  270. set_current_state(TASK_INTERRUPTIBLE);
  271. data = atomic_xchg(&lis3_dev.count, 0);
  272. if (data)
  273. break;
  274. if (file->f_flags & O_NONBLOCK) {
  275. retval = -EAGAIN;
  276. goto out;
  277. }
  278. if (signal_pending(current)) {
  279. retval = -ERESTARTSYS;
  280. goto out;
  281. }
  282. schedule();
  283. }
  284. if (data < 255)
  285. byte_data = data;
  286. else
  287. byte_data = 255;
  288. /* make sure we are not going into copy_to_user() with
  289. * TASK_INTERRUPTIBLE state */
  290. set_current_state(TASK_RUNNING);
  291. if (copy_to_user(buf, &byte_data, sizeof(byte_data)))
  292. retval = -EFAULT;
  293. out:
  294. __set_current_state(TASK_RUNNING);
  295. remove_wait_queue(&lis3_dev.misc_wait, &wait);
  296. return retval;
  297. }
  298. static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
  299. {
  300. poll_wait(file, &lis3_dev.misc_wait, wait);
  301. if (atomic_read(&lis3_dev.count))
  302. return POLLIN | POLLRDNORM;
  303. return 0;
  304. }
  305. static int lis3lv02d_misc_fasync(int fd, struct file *file, int on)
  306. {
  307. return fasync_helper(fd, file, on, &lis3_dev.async_queue);
  308. }
  309. static const struct file_operations lis3lv02d_misc_fops = {
  310. .owner = THIS_MODULE,
  311. .llseek = no_llseek,
  312. .read = lis3lv02d_misc_read,
  313. .open = lis3lv02d_misc_open,
  314. .release = lis3lv02d_misc_release,
  315. .poll = lis3lv02d_misc_poll,
  316. .fasync = lis3lv02d_misc_fasync,
  317. };
  318. static struct miscdevice lis3lv02d_misc_device = {
  319. .minor = MISC_DYNAMIC_MINOR,
  320. .name = "freefall",
  321. .fops = &lis3lv02d_misc_fops,
  322. };
  323. static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev)
  324. {
  325. int x, y, z;
  326. lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z);
  327. input_report_abs(pidev->input, ABS_X, x);
  328. input_report_abs(pidev->input, ABS_Y, y);
  329. input_report_abs(pidev->input, ABS_Z, z);
  330. input_sync(pidev->input);
  331. }
  332. int lis3lv02d_joystick_enable(void)
  333. {
  334. struct input_dev *input_dev;
  335. int err;
  336. int max_val, fuzz, flat;
  337. if (lis3_dev.idev)
  338. return -EINVAL;
  339. lis3_dev.idev = input_allocate_polled_device();
  340. if (!lis3_dev.idev)
  341. return -ENOMEM;
  342. lis3_dev.idev->poll = lis3lv02d_joystick_poll;
  343. lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL;
  344. input_dev = lis3_dev.idev->input;
  345. input_dev->name = "ST LIS3LV02DL Accelerometer";
  346. input_dev->phys = DRIVER_NAME "/input0";
  347. input_dev->id.bustype = BUS_HOST;
  348. input_dev->id.vendor = 0;
  349. input_dev->dev.parent = &lis3_dev.pdev->dev;
  350. set_bit(EV_ABS, input_dev->evbit);
  351. max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY;
  352. fuzz = (LIS3_DEFAULT_FUZZ * lis3_dev.scale) / LIS3_ACCURACY;
  353. flat = (LIS3_DEFAULT_FLAT * lis3_dev.scale) / LIS3_ACCURACY;
  354. input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat);
  355. input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat);
  356. input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat);
  357. err = input_register_polled_device(lis3_dev.idev);
  358. if (err) {
  359. input_free_polled_device(lis3_dev.idev);
  360. lis3_dev.idev = NULL;
  361. }
  362. return err;
  363. }
  364. EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable);
  365. void lis3lv02d_joystick_disable(void)
  366. {
  367. if (!lis3_dev.idev)
  368. return;
  369. if (lis3_dev.irq)
  370. misc_deregister(&lis3lv02d_misc_device);
  371. input_unregister_polled_device(lis3_dev.idev);
  372. input_free_polled_device(lis3_dev.idev);
  373. lis3_dev.idev = NULL;
  374. }
  375. EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);
  376. /* Sysfs stuff */
  377. static ssize_t lis3lv02d_selftest_show(struct device *dev,
  378. struct device_attribute *attr, char *buf)
  379. {
  380. int result;
  381. s16 values[3];
  382. result = lis3lv02d_selftest(&lis3_dev, values);
  383. return sprintf(buf, "%s %d %d %d\n", result == 0 ? "OK" : "FAIL",
  384. values[0], values[1], values[2]);
  385. }
  386. static ssize_t lis3lv02d_position_show(struct device *dev,
  387. struct device_attribute *attr, char *buf)
  388. {
  389. int x, y, z;
  390. lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z);
  391. return sprintf(buf, "(%d,%d,%d)\n", x, y, z);
  392. }
  393. static ssize_t lis3lv02d_rate_show(struct device *dev,
  394. struct device_attribute *attr, char *buf)
  395. {
  396. return sprintf(buf, "%d\n", lis3lv02d_get_odr());
  397. }
  398. static ssize_t lis3lv02d_rate_set(struct device *dev,
  399. struct device_attribute *attr, const char *buf,
  400. size_t count)
  401. {
  402. unsigned long rate;
  403. if (strict_strtoul(buf, 0, &rate))
  404. return -EINVAL;
  405. if (lis3lv02d_set_odr(rate))
  406. return -EINVAL;
  407. return count;
  408. }
  409. static DEVICE_ATTR(selftest, S_IRUSR, lis3lv02d_selftest_show, NULL);
  410. static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL);
  411. static DEVICE_ATTR(rate, S_IRUGO | S_IWUSR, lis3lv02d_rate_show,
  412. lis3lv02d_rate_set);
  413. static struct attribute *lis3lv02d_attributes[] = {
  414. &dev_attr_selftest.attr,
  415. &dev_attr_position.attr,
  416. &dev_attr_rate.attr,
  417. NULL
  418. };
  419. static struct attribute_group lis3lv02d_attribute_group = {
  420. .attrs = lis3lv02d_attributes
  421. };
  422. static int lis3lv02d_add_fs(struct lis3lv02d *lis3)
  423. {
  424. lis3->pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
  425. if (IS_ERR(lis3->pdev))
  426. return PTR_ERR(lis3->pdev);
  427. return sysfs_create_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group);
  428. }
  429. int lis3lv02d_remove_fs(struct lis3lv02d *lis3)
  430. {
  431. sysfs_remove_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group);
  432. platform_device_unregister(lis3->pdev);
  433. return 0;
  434. }
  435. EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs);
  436. /*
  437. * Initialise the accelerometer and the various subsystems.
  438. * Should be rather independent of the bus system.
  439. */
  440. int lis3lv02d_init_device(struct lis3lv02d *dev)
  441. {
  442. dev->whoami = lis3lv02d_read_8(dev, WHO_AM_I);
  443. switch (dev->whoami) {
  444. case WAI_12B:
  445. printk(KERN_INFO DRIVER_NAME ": 12 bits sensor found\n");
  446. dev->read_data = lis3lv02d_read_12;
  447. dev->mdps_max_val = 2048;
  448. dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B;
  449. dev->odrs = lis3_12_rates;
  450. dev->odr_mask = CTRL1_DF0 | CTRL1_DF1;
  451. dev->scale = LIS3_SENSITIVITY_12B;
  452. break;
  453. case WAI_8B:
  454. printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n");
  455. dev->read_data = lis3lv02d_read_8;
  456. dev->mdps_max_val = 128;
  457. dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
  458. dev->odrs = lis3_8_rates;
  459. dev->odr_mask = CTRL1_DR;
  460. dev->scale = LIS3_SENSITIVITY_8B;
  461. break;
  462. default:
  463. printk(KERN_ERR DRIVER_NAME
  464. ": unknown sensor type 0x%X\n", dev->whoami);
  465. return -EINVAL;
  466. }
  467. mutex_init(&dev->mutex);
  468. lis3lv02d_add_fs(dev);
  469. lis3lv02d_poweron(dev);
  470. if (lis3lv02d_joystick_enable())
  471. printk(KERN_ERR DRIVER_NAME ": joystick initialization failed\n");
  472. /* passing in platform specific data is purely optional and only
  473. * used by the SPI transport layer at the moment */
  474. if (dev->pdata) {
  475. struct lis3lv02d_platform_data *p = dev->pdata;
  476. if (p->click_flags && (dev->whoami == WAI_8B)) {
  477. dev->write(dev, CLICK_CFG, p->click_flags);
  478. dev->write(dev, CLICK_TIMELIMIT, p->click_time_limit);
  479. dev->write(dev, CLICK_LATENCY, p->click_latency);
  480. dev->write(dev, CLICK_WINDOW, p->click_window);
  481. dev->write(dev, CLICK_THSZ, p->click_thresh_z & 0xf);
  482. dev->write(dev, CLICK_THSY_X,
  483. (p->click_thresh_x & 0xf) |
  484. (p->click_thresh_y << 4));
  485. }
  486. if (p->wakeup_flags && (dev->whoami == WAI_8B)) {
  487. dev->write(dev, FF_WU_CFG_1, p->wakeup_flags);
  488. dev->write(dev, FF_WU_THS_1, p->wakeup_thresh & 0x7f);
  489. /* default to 2.5ms for now */
  490. dev->write(dev, FF_WU_DURATION_1, 1);
  491. /* enable high pass filter for both free-fall units */
  492. dev->write(dev, CTRL_REG2, HP_FF_WU1 | HP_FF_WU2);
  493. }
  494. if (p->irq_cfg)
  495. dev->write(dev, CTRL_REG3, p->irq_cfg);
  496. }
  497. /* bail if we did not get an IRQ from the bus layer */
  498. if (!dev->irq) {
  499. printk(KERN_ERR DRIVER_NAME
  500. ": No IRQ. Disabling /dev/freefall\n");
  501. goto out;
  502. }
  503. if (misc_register(&lis3lv02d_misc_device))
  504. printk(KERN_ERR DRIVER_NAME ": misc_register failed\n");
  505. out:
  506. return 0;
  507. }
  508. EXPORT_SYMBOL_GPL(lis3lv02d_init_device);
  509. MODULE_DESCRIPTION("ST LIS3LV02Dx three-axis digital accelerometer driver");
  510. MODULE_AUTHOR("Yan Burman, Eric Piel, Pavel Machek");
  511. MODULE_LICENSE("GPL");