blob: 4888ac5ba8cc429af80858c0cab88cb1c0e2ad7c [file] [log] [blame]
Pavel Machek455fbdd2008-11-12 13:27:02 -08001/*
2 * lis3lv02d.c - ST LIS3LV02DL accelerometer driver
3 *
4 * Copyright (C) 2007-2008 Yan Burman
5 * Copyright (C) 2008 Eric Piel
Pavel Machekef2cfc72009-02-18 14:48:23 -08006 * Copyright (C) 2008-2009 Pavel Machek
Pavel Machek455fbdd2008-11-12 13:27:02 -08007 *
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>
30#include <linux/input.h>
31#include <linux/kthread.h>
32#include <linux/semaphore.h>
33#include <linux/delay.h>
34#include <linux/wait.h>
35#include <linux/poll.h>
36#include <linux/freezer.h>
Pavel Machek455fbdd2008-11-12 13:27:02 -080037#include <linux/uaccess.h>
Pavel Machekef2cfc72009-02-18 14:48:23 -080038#include <linux/miscdevice.h>
Pavel Machek455fbdd2008-11-12 13:27:02 -080039#include <acpi/acpi_drivers.h>
40#include <asm/atomic.h>
41#include "lis3lv02d.h"
42
43#define DRIVER_NAME "lis3lv02d"
Pavel Machek455fbdd2008-11-12 13:27:02 -080044
45/* joystick device poll interval in milliseconds */
46#define MDPS_POLL_INTERVAL 50
47/*
48 * The sensor can also generate interrupts (DRDY) but it's pretty pointless
49 * because their are generated even if the data do not change. So it's better
50 * to keep the interrupt for the free-fall event. The values are updated at
51 * 40Hz (at the lowest frequency), but as it can be pretty time consuming on
52 * some low processor, we poll the sensor only at 20Hz... enough for the
53 * joystick.
54 */
55
Pavel Machekbe84cfc2009-03-31 15:24:26 -070056struct acpi_lis3lv02d lis3_dev = {
57 .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait),
Pavel Machekef2cfc72009-02-18 14:48:23 -080058};
59
Pavel Machekbe84cfc2009-03-31 15:24:26 -070060EXPORT_SYMBOL_GPL(lis3_dev);
Pavel Machek455fbdd2008-11-12 13:27:02 -080061
Pavel Machek455fbdd2008-11-12 13:27:02 -080062static int lis3lv02d_add_fs(struct acpi_device *device);
63
Pavel Machekbe84cfc2009-03-31 15:24:26 -070064static s16 lis3lv02d_read_16(acpi_handle handle, int reg)
65{
66 u8 lo, hi;
67
68 lis3_dev.read(handle, reg, &lo);
69 lis3_dev.read(handle, reg + 1, &hi);
70 /* In "12 bit right justified" mode, bit 6, bit 7, bit 8 = bit 5 */
71 return (s16)((hi << 8) | lo);
72}
73
Pavel Machek455fbdd2008-11-12 13:27:02 -080074/**
75 * lis3lv02d_get_axis - For the given axis, give the value converted
76 * @axis: 1,2,3 - can also be negative
77 * @hw_values: raw values returned by the hardware
78 *
79 * Returns the converted value.
80 */
81static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3])
82{
83 if (axis > 0)
84 return hw_values[axis - 1];
85 else
86 return -hw_values[-axis - 1];
87}
88
89/**
90 * lis3lv02d_get_xyz - Get X, Y and Z axis values from the accelerometer
91 * @handle: the handle to the device
92 * @x: where to store the X axis value
93 * @y: where to store the Y axis value
94 * @z: where to store the Z axis value
95 *
96 * Note that 40Hz input device can eat up about 10% CPU at 800MHZ
97 */
98static void lis3lv02d_get_xyz(acpi_handle handle, int *x, int *y, int *z)
99{
100 int position[3];
101
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700102 position[0] = lis3_dev.read_data(handle, OUTX);
103 position[1] = lis3_dev.read_data(handle, OUTY);
104 position[2] = lis3_dev.read_data(handle, OUTZ);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800105
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700106 *x = lis3lv02d_get_axis(lis3_dev.ac.x, position);
107 *y = lis3lv02d_get_axis(lis3_dev.ac.y, position);
108 *z = lis3lv02d_get_axis(lis3_dev.ac.z, position);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800109}
110
Eric Pielcfce41a2009-01-09 16:41:01 -0800111void lis3lv02d_poweroff(acpi_handle handle)
Pavel Machek455fbdd2008-11-12 13:27:02 -0800112{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700113 lis3_dev.is_on = 0;
Pavel Machek455fbdd2008-11-12 13:27:02 -0800114}
Eric Pielcfce41a2009-01-09 16:41:01 -0800115EXPORT_SYMBOL_GPL(lis3lv02d_poweroff);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800116
Eric Pielcfce41a2009-01-09 16:41:01 -0800117void lis3lv02d_poweron(acpi_handle handle)
Pavel Machek455fbdd2008-11-12 13:27:02 -0800118{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700119 lis3_dev.is_on = 1;
120 lis3_dev.init(handle);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800121}
Eric Pielcfce41a2009-01-09 16:41:01 -0800122EXPORT_SYMBOL_GPL(lis3lv02d_poweron);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800123
124/*
125 * To be called before starting to use the device. It makes sure that the
126 * device will always be on until a call to lis3lv02d_decrease_use(). Not to be
127 * used from interrupt context.
128 */
129static void lis3lv02d_increase_use(struct acpi_lis3lv02d *dev)
130{
131 mutex_lock(&dev->lock);
132 dev->usage++;
133 if (dev->usage == 1) {
134 if (!dev->is_on)
135 lis3lv02d_poweron(dev->device->handle);
136 }
137 mutex_unlock(&dev->lock);
138}
139
140/*
141 * To be called whenever a usage of the device is stopped.
142 * It will make sure to turn off the device when there is not usage.
143 */
144static void lis3lv02d_decrease_use(struct acpi_lis3lv02d *dev)
145{
146 mutex_lock(&dev->lock);
147 dev->usage--;
148 if (dev->usage == 0)
149 lis3lv02d_poweroff(dev->device->handle);
150 mutex_unlock(&dev->lock);
151}
152
Pavel Machekef2cfc72009-02-18 14:48:23 -0800153static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
154{
155 /*
156 * Be careful: on some HP laptops the bios force DD when on battery and
157 * the lid is closed. This leads to interrupts as soon as a little move
158 * is done.
159 */
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700160 atomic_inc(&lis3_dev.count);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800161
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700162 wake_up_interruptible(&lis3_dev.misc_wait);
163 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800164 return IRQ_HANDLED;
165}
166
167static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
168{
169 int ret;
170
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700171 if (test_and_set_bit(0, &lis3_dev.misc_opened))
Pavel Machekef2cfc72009-02-18 14:48:23 -0800172 return -EBUSY; /* already open */
173
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700174 atomic_set(&lis3_dev.count, 0);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800175
176 /*
177 * The sensor can generate interrupts for free-fall and direction
178 * detection (distinguishable with FF_WU_SRC and DD_SRC) but to keep
179 * the things simple and _fast_ we activate it only for free-fall, so
180 * no need to read register (very slow with ACPI). For the same reason,
181 * we forbid shared interrupts.
182 *
183 * IRQF_TRIGGER_RISING seems pointless on HP laptops because the
184 * io-apic is not configurable (and generates a warning) but I keep it
185 * in case of support for other hardware.
186 */
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700187 ret = request_irq(lis3_dev.irq, lis302dl_interrupt, IRQF_TRIGGER_RISING,
188 DRIVER_NAME, &lis3_dev);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800189
190 if (ret) {
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700191 clear_bit(0, &lis3_dev.misc_opened);
192 printk(KERN_ERR DRIVER_NAME ": IRQ%d allocation failed\n", lis3_dev.irq);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800193 return -EBUSY;
194 }
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700195 lis3lv02d_increase_use(&lis3_dev);
196 printk("lis3: registered interrupt %d\n", lis3_dev.irq);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800197 return 0;
198}
199
200static int lis3lv02d_misc_release(struct inode *inode, struct file *file)
201{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700202 fasync_helper(-1, file, 0, &lis3_dev.async_queue);
203 lis3lv02d_decrease_use(&lis3_dev);
204 free_irq(lis3_dev.irq, &lis3_dev);
205 clear_bit(0, &lis3_dev.misc_opened); /* release the device */
Pavel Machekef2cfc72009-02-18 14:48:23 -0800206 return 0;
207}
208
209static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
210 size_t count, loff_t *pos)
211{
212 DECLARE_WAITQUEUE(wait, current);
213 u32 data;
214 unsigned char byte_data;
215 ssize_t retval = 1;
216
217 if (count < 1)
218 return -EINVAL;
219
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700220 add_wait_queue(&lis3_dev.misc_wait, &wait);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800221 while (true) {
222 set_current_state(TASK_INTERRUPTIBLE);
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700223 data = atomic_xchg(&lis3_dev.count, 0);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800224 if (data)
225 break;
226
227 if (file->f_flags & O_NONBLOCK) {
228 retval = -EAGAIN;
229 goto out;
230 }
231
232 if (signal_pending(current)) {
233 retval = -ERESTARTSYS;
234 goto out;
235 }
236
237 schedule();
238 }
239
240 if (data < 255)
241 byte_data = data;
242 else
243 byte_data = 255;
244
245 /* make sure we are not going into copy_to_user() with
246 * TASK_INTERRUPTIBLE state */
247 set_current_state(TASK_RUNNING);
248 if (copy_to_user(buf, &byte_data, sizeof(byte_data)))
249 retval = -EFAULT;
250
251out:
252 __set_current_state(TASK_RUNNING);
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700253 remove_wait_queue(&lis3_dev.misc_wait, &wait);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800254
255 return retval;
256}
257
258static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
259{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700260 poll_wait(file, &lis3_dev.misc_wait, wait);
261 if (atomic_read(&lis3_dev.count))
Pavel Machekef2cfc72009-02-18 14:48:23 -0800262 return POLLIN | POLLRDNORM;
263 return 0;
264}
265
266static int lis3lv02d_misc_fasync(int fd, struct file *file, int on)
267{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700268 return fasync_helper(fd, file, on, &lis3_dev.async_queue);
Pavel Machekef2cfc72009-02-18 14:48:23 -0800269}
270
271static const struct file_operations lis3lv02d_misc_fops = {
272 .owner = THIS_MODULE,
273 .llseek = no_llseek,
274 .read = lis3lv02d_misc_read,
275 .open = lis3lv02d_misc_open,
276 .release = lis3lv02d_misc_release,
277 .poll = lis3lv02d_misc_poll,
278 .fasync = lis3lv02d_misc_fasync,
279};
280
281static struct miscdevice lis3lv02d_misc_device = {
282 .minor = MISC_DYNAMIC_MINOR,
283 .name = "freefall",
284 .fops = &lis3lv02d_misc_fops,
285};
286
Pavel Machek455fbdd2008-11-12 13:27:02 -0800287/**
288 * lis3lv02d_joystick_kthread - Kthread polling function
289 * @data: unused - here to conform to threadfn prototype
290 */
291static int lis3lv02d_joystick_kthread(void *data)
292{
293 int x, y, z;
294
295 while (!kthread_should_stop()) {
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700296 lis3lv02d_get_xyz(lis3_dev.device->handle, &x, &y, &z);
297 input_report_abs(lis3_dev.idev, ABS_X, x - lis3_dev.xcalib);
298 input_report_abs(lis3_dev.idev, ABS_Y, y - lis3_dev.ycalib);
299 input_report_abs(lis3_dev.idev, ABS_Z, z - lis3_dev.zcalib);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800300
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700301 input_sync(lis3_dev.idev);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800302
303 try_to_freeze();
304 msleep_interruptible(MDPS_POLL_INTERVAL);
305 }
306
307 return 0;
308}
309
310static int lis3lv02d_joystick_open(struct input_dev *input)
311{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700312 lis3lv02d_increase_use(&lis3_dev);
313 lis3_dev.kthread = kthread_run(lis3lv02d_joystick_kthread, NULL, "klis3lv02d");
314 if (IS_ERR(lis3_dev.kthread)) {
315 lis3lv02d_decrease_use(&lis3_dev);
316 return PTR_ERR(lis3_dev.kthread);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800317 }
318
319 return 0;
320}
321
322static void lis3lv02d_joystick_close(struct input_dev *input)
323{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700324 kthread_stop(lis3_dev.kthread);
325 lis3lv02d_decrease_use(&lis3_dev);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800326}
327
Pavel Machek455fbdd2008-11-12 13:27:02 -0800328static inline void lis3lv02d_calibrate_joystick(void)
329{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700330 lis3lv02d_get_xyz(lis3_dev.device->handle, &lis3_dev.xcalib, &lis3_dev.ycalib, &lis3_dev.zcalib);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800331}
332
Eric Pielcfce41a2009-01-09 16:41:01 -0800333int lis3lv02d_joystick_enable(void)
Pavel Machek455fbdd2008-11-12 13:27:02 -0800334{
335 int err;
336
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700337 if (lis3_dev.idev)
Pavel Machek455fbdd2008-11-12 13:27:02 -0800338 return -EINVAL;
339
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700340 lis3_dev.idev = input_allocate_device();
341 if (!lis3_dev.idev)
Pavel Machek455fbdd2008-11-12 13:27:02 -0800342 return -ENOMEM;
343
344 lis3lv02d_calibrate_joystick();
345
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700346 lis3_dev.idev->name = "ST LIS3LV02DL Accelerometer";
347 lis3_dev.idev->phys = DRIVER_NAME "/input0";
348 lis3_dev.idev->id.bustype = BUS_HOST;
349 lis3_dev.idev->id.vendor = 0;
350 lis3_dev.idev->dev.parent = &lis3_dev.pdev->dev;
351 lis3_dev.idev->open = lis3lv02d_joystick_open;
352 lis3_dev.idev->close = lis3lv02d_joystick_close;
Pavel Machek455fbdd2008-11-12 13:27:02 -0800353
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700354 set_bit(EV_ABS, lis3_dev.idev->evbit);
355 input_set_abs_params(lis3_dev.idev, ABS_X, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
356 input_set_abs_params(lis3_dev.idev, ABS_Y, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
357 input_set_abs_params(lis3_dev.idev, ABS_Z, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800358
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700359 err = input_register_device(lis3_dev.idev);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800360 if (err) {
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700361 input_free_device(lis3_dev.idev);
362 lis3_dev.idev = NULL;
Pavel Machek455fbdd2008-11-12 13:27:02 -0800363 }
364
365 return err;
366}
Eric Pielcfce41a2009-01-09 16:41:01 -0800367EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800368
Eric Pielcfce41a2009-01-09 16:41:01 -0800369void lis3lv02d_joystick_disable(void)
Pavel Machek455fbdd2008-11-12 13:27:02 -0800370{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700371 if (!lis3_dev.idev)
Pavel Machek455fbdd2008-11-12 13:27:02 -0800372 return;
373
Pavel Machekef2cfc72009-02-18 14:48:23 -0800374 misc_deregister(&lis3lv02d_misc_device);
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700375 input_unregister_device(lis3_dev.idev);
376 lis3_dev.idev = NULL;
Pavel Machek455fbdd2008-11-12 13:27:02 -0800377}
Eric Pielcfce41a2009-01-09 16:41:01 -0800378EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800379
380/*
381 * Initialise the accelerometer and the various subsystems.
382 * Should be rather independant of the bus system.
383 */
Eric Pielcfce41a2009-01-09 16:41:01 -0800384int lis3lv02d_init_device(struct acpi_lis3lv02d *dev)
Pavel Machek455fbdd2008-11-12 13:27:02 -0800385{
386 mutex_init(&dev->lock);
387 lis3lv02d_add_fs(dev->device);
388 lis3lv02d_increase_use(dev);
389
390 if (lis3lv02d_joystick_enable())
391 printk(KERN_ERR DRIVER_NAME ": joystick initialization failed\n");
392
Pavel Machekef2cfc72009-02-18 14:48:23 -0800393 printk("lis3_init_device: irq %d\n", dev->irq);
394
395 /* if we did not get an IRQ from ACPI - we have nothing more to do */
396 if (!dev->irq) {
397 printk(KERN_ERR DRIVER_NAME
398 ": No IRQ in ACPI. Disabling /dev/freefall\n");
399 goto out;
400 }
401
402 printk("lis3: registering device\n");
403 if (misc_register(&lis3lv02d_misc_device))
404 printk(KERN_ERR DRIVER_NAME ": misc_register failed\n");
405out:
Pavel Machek455fbdd2008-11-12 13:27:02 -0800406 lis3lv02d_decrease_use(dev);
407 return 0;
408}
Eric Pielcfce41a2009-01-09 16:41:01 -0800409EXPORT_SYMBOL_GPL(lis3lv02d_init_device);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800410
411/* Sysfs stuff */
412static ssize_t lis3lv02d_position_show(struct device *dev,
413 struct device_attribute *attr, char *buf)
414{
415 int x, y, z;
416
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700417 lis3lv02d_increase_use(&lis3_dev);
418 lis3lv02d_get_xyz(lis3_dev.device->handle, &x, &y, &z);
419 lis3lv02d_decrease_use(&lis3_dev);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800420 return sprintf(buf, "(%d,%d,%d)\n", x, y, z);
421}
422
423static ssize_t lis3lv02d_calibrate_show(struct device *dev,
424 struct device_attribute *attr, char *buf)
425{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700426 return sprintf(buf, "(%d,%d,%d)\n", lis3_dev.xcalib, lis3_dev.ycalib, lis3_dev.zcalib);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800427}
428
429static ssize_t lis3lv02d_calibrate_store(struct device *dev,
430 struct device_attribute *attr,
431 const char *buf, size_t count)
432{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700433 lis3lv02d_increase_use(&lis3_dev);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800434 lis3lv02d_calibrate_joystick();
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700435 lis3lv02d_decrease_use(&lis3_dev);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800436 return count;
437}
438
439/* conversion btw sampling rate and the register values */
440static int lis3lv02dl_df_val[4] = {40, 160, 640, 2560};
441static ssize_t lis3lv02d_rate_show(struct device *dev,
442 struct device_attribute *attr, char *buf)
443{
444 u8 ctrl;
445 int val;
446
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700447 lis3lv02d_increase_use(&lis3_dev);
448 lis3_dev.read(lis3_dev.device->handle, CTRL_REG1, &ctrl);
449 lis3lv02d_decrease_use(&lis3_dev);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800450 val = (ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4;
451 return sprintf(buf, "%d\n", lis3lv02dl_df_val[val]);
452}
453
454static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL);
455static DEVICE_ATTR(calibrate, S_IRUGO|S_IWUSR, lis3lv02d_calibrate_show,
456 lis3lv02d_calibrate_store);
457static DEVICE_ATTR(rate, S_IRUGO, lis3lv02d_rate_show, NULL);
458
459static struct attribute *lis3lv02d_attributes[] = {
460 &dev_attr_position.attr,
461 &dev_attr_calibrate.attr,
462 &dev_attr_rate.attr,
463 NULL
464};
465
466static struct attribute_group lis3lv02d_attribute_group = {
467 .attrs = lis3lv02d_attributes
468};
469
Eric Pielcfce41a2009-01-09 16:41:01 -0800470
Pavel Machek455fbdd2008-11-12 13:27:02 -0800471static int lis3lv02d_add_fs(struct acpi_device *device)
472{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700473 lis3_dev.pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
474 if (IS_ERR(lis3_dev.pdev))
475 return PTR_ERR(lis3_dev.pdev);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800476
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700477 return sysfs_create_group(&lis3_dev.pdev->dev.kobj, &lis3lv02d_attribute_group);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800478}
479
Eric Pielcfce41a2009-01-09 16:41:01 -0800480int lis3lv02d_remove_fs(void)
Pavel Machek455fbdd2008-11-12 13:27:02 -0800481{
Pavel Machekbe84cfc2009-03-31 15:24:26 -0700482 sysfs_remove_group(&lis3_dev.pdev->dev.kobj, &lis3lv02d_attribute_group);
483 platform_device_unregister(lis3_dev.pdev);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800484 return 0;
485}
Eric Pielcfce41a2009-01-09 16:41:01 -0800486EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs);
Pavel Machek455fbdd2008-11-12 13:27:02 -0800487
488MODULE_DESCRIPTION("ST LIS3LV02Dx three-axis digital accelerometer driver");
Pavel Machekef2cfc72009-02-18 14:48:23 -0800489MODULE_AUTHOR("Yan Burman, Eric Piel, Pavel Machek");
Pavel Machek455fbdd2008-11-12 13:27:02 -0800490MODULE_LICENSE("GPL");
491