aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lis3lv02d.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lis3lv02d.c')
-rw-r--r--drivers/hwmon/lis3lv02d.c172
1 files changed, 91 insertions, 81 deletions
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index 8bb2158f0453..4888ac5ba8cc 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -53,14 +53,24 @@
53 * joystick. 53 * joystick.
54 */ 54 */
55 55
56struct acpi_lis3lv02d adev = { 56struct acpi_lis3lv02d lis3_dev = {
57 .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(adev.misc_wait), 57 .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait),
58}; 58};
59 59
60EXPORT_SYMBOL_GPL(adev); 60EXPORT_SYMBOL_GPL(lis3_dev);
61 61
62static int lis3lv02d_add_fs(struct acpi_device *device); 62static int lis3lv02d_add_fs(struct acpi_device *device);
63 63
64static 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
64/** 74/**
65 * lis3lv02d_get_axis - For the given axis, give the value converted 75 * lis3lv02d_get_axis - For the given axis, give the value converted
66 * @axis: 1,2,3 - can also be negative 76 * @axis: 1,2,3 - can also be negative
@@ -89,25 +99,25 @@ static void lis3lv02d_get_xyz(acpi_handle handle, int *x, int *y, int *z)
89{ 99{
90 int position[3]; 100 int position[3];
91 101
92 position[0] = adev.read_data(handle, OUTX); 102 position[0] = lis3_dev.read_data(handle, OUTX);
93 position[1] = adev.read_data(handle, OUTY); 103 position[1] = lis3_dev.read_data(handle, OUTY);
94 position[2] = adev.read_data(handle, OUTZ); 104 position[2] = lis3_dev.read_data(handle, OUTZ);
95 105
96 *x = lis3lv02d_get_axis(adev.ac.x, position); 106 *x = lis3lv02d_get_axis(lis3_dev.ac.x, position);
97 *y = lis3lv02d_get_axis(adev.ac.y, position); 107 *y = lis3lv02d_get_axis(lis3_dev.ac.y, position);
98 *z = lis3lv02d_get_axis(adev.ac.z, position); 108 *z = lis3lv02d_get_axis(lis3_dev.ac.z, position);
99} 109}
100 110
101void lis3lv02d_poweroff(acpi_handle handle) 111void lis3lv02d_poweroff(acpi_handle handle)
102{ 112{
103 adev.is_on = 0; 113 lis3_dev.is_on = 0;
104} 114}
105EXPORT_SYMBOL_GPL(lis3lv02d_poweroff); 115EXPORT_SYMBOL_GPL(lis3lv02d_poweroff);
106 116
107void lis3lv02d_poweron(acpi_handle handle) 117void lis3lv02d_poweron(acpi_handle handle)
108{ 118{
109 adev.is_on = 1; 119 lis3_dev.is_on = 1;
110 adev.init(handle); 120 lis3_dev.init(handle);
111} 121}
112EXPORT_SYMBOL_GPL(lis3lv02d_poweron); 122EXPORT_SYMBOL_GPL(lis3lv02d_poweron);
113 123
@@ -147,10 +157,10 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
147 * the lid is closed. This leads to interrupts as soon as a little move 157 * the lid is closed. This leads to interrupts as soon as a little move
148 * is done. 158 * is done.
149 */ 159 */
150 atomic_inc(&adev.count); 160 atomic_inc(&lis3_dev.count);
151 161
152 wake_up_interruptible(&adev.misc_wait); 162 wake_up_interruptible(&lis3_dev.misc_wait);
153 kill_fasync(&adev.async_queue, SIGIO, POLL_IN); 163 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
154 return IRQ_HANDLED; 164 return IRQ_HANDLED;
155} 165}
156 166
@@ -158,10 +168,10 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
158{ 168{
159 int ret; 169 int ret;
160 170
161 if (test_and_set_bit(0, &adev.misc_opened)) 171 if (test_and_set_bit(0, &lis3_dev.misc_opened))
162 return -EBUSY; /* already open */ 172 return -EBUSY; /* already open */
163 173
164 atomic_set(&adev.count, 0); 174 atomic_set(&lis3_dev.count, 0);
165 175
166 /* 176 /*
167 * The sensor can generate interrupts for free-fall and direction 177 * The sensor can generate interrupts for free-fall and direction
@@ -174,25 +184,25 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
174 * io-apic is not configurable (and generates a warning) but I keep it 184 * io-apic is not configurable (and generates a warning) but I keep it
175 * in case of support for other hardware. 185 * in case of support for other hardware.
176 */ 186 */
177 ret = request_irq(adev.irq, lis302dl_interrupt, IRQF_TRIGGER_RISING, 187 ret = request_irq(lis3_dev.irq, lis302dl_interrupt, IRQF_TRIGGER_RISING,
178 DRIVER_NAME, &adev); 188 DRIVER_NAME, &lis3_dev);
179 189
180 if (ret) { 190 if (ret) {
181 clear_bit(0, &adev.misc_opened); 191 clear_bit(0, &lis3_dev.misc_opened);
182 printk(KERN_ERR DRIVER_NAME ": IRQ%d allocation failed\n", adev.irq); 192 printk(KERN_ERR DRIVER_NAME ": IRQ%d allocation failed\n", lis3_dev.irq);
183 return -EBUSY; 193 return -EBUSY;
184 } 194 }
185 lis3lv02d_increase_use(&adev); 195 lis3lv02d_increase_use(&lis3_dev);
186 printk("lis3: registered interrupt %d\n", adev.irq); 196 printk("lis3: registered interrupt %d\n", lis3_dev.irq);
187 return 0; 197 return 0;
188} 198}
189 199
190static int lis3lv02d_misc_release(struct inode *inode, struct file *file) 200static int lis3lv02d_misc_release(struct inode *inode, struct file *file)
191{ 201{
192 fasync_helper(-1, file, 0, &adev.async_queue); 202 fasync_helper(-1, file, 0, &lis3_dev.async_queue);
193 lis3lv02d_decrease_use(&adev); 203 lis3lv02d_decrease_use(&lis3_dev);
194 free_irq(adev.irq, &adev); 204 free_irq(lis3_dev.irq, &lis3_dev);
195 clear_bit(0, &adev.misc_opened); /* release the device */ 205 clear_bit(0, &lis3_dev.misc_opened); /* release the device */
196 return 0; 206 return 0;
197} 207}
198 208
@@ -207,10 +217,10 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
207 if (count < 1) 217 if (count < 1)
208 return -EINVAL; 218 return -EINVAL;
209 219
210 add_wait_queue(&adev.misc_wait, &wait); 220 add_wait_queue(&lis3_dev.misc_wait, &wait);
211 while (true) { 221 while (true) {
212 set_current_state(TASK_INTERRUPTIBLE); 222 set_current_state(TASK_INTERRUPTIBLE);
213 data = atomic_xchg(&adev.count, 0); 223 data = atomic_xchg(&lis3_dev.count, 0);
214 if (data) 224 if (data)
215 break; 225 break;
216 226
@@ -240,22 +250,22 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
240 250
241out: 251out:
242 __set_current_state(TASK_RUNNING); 252 __set_current_state(TASK_RUNNING);
243 remove_wait_queue(&adev.misc_wait, &wait); 253 remove_wait_queue(&lis3_dev.misc_wait, &wait);
244 254
245 return retval; 255 return retval;
246} 256}
247 257
248static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait) 258static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
249{ 259{
250 poll_wait(file, &adev.misc_wait, wait); 260 poll_wait(file, &lis3_dev.misc_wait, wait);
251 if (atomic_read(&adev.count)) 261 if (atomic_read(&lis3_dev.count))
252 return POLLIN | POLLRDNORM; 262 return POLLIN | POLLRDNORM;
253 return 0; 263 return 0;
254} 264}
255 265
256static int lis3lv02d_misc_fasync(int fd, struct file *file, int on) 266static int lis3lv02d_misc_fasync(int fd, struct file *file, int on)
257{ 267{
258 return fasync_helper(fd, file, on, &adev.async_queue); 268 return fasync_helper(fd, file, on, &lis3_dev.async_queue);
259} 269}
260 270
261static const struct file_operations lis3lv02d_misc_fops = { 271static const struct file_operations lis3lv02d_misc_fops = {
@@ -283,12 +293,12 @@ static int lis3lv02d_joystick_kthread(void *data)
283 int x, y, z; 293 int x, y, z;
284 294
285 while (!kthread_should_stop()) { 295 while (!kthread_should_stop()) {
286 lis3lv02d_get_xyz(adev.device->handle, &x, &y, &z); 296 lis3lv02d_get_xyz(lis3_dev.device->handle, &x, &y, &z);
287 input_report_abs(adev.idev, ABS_X, x - adev.xcalib); 297 input_report_abs(lis3_dev.idev, ABS_X, x - lis3_dev.xcalib);
288 input_report_abs(adev.idev, ABS_Y, y - adev.ycalib); 298 input_report_abs(lis3_dev.idev, ABS_Y, y - lis3_dev.ycalib);
289 input_report_abs(adev.idev, ABS_Z, z - adev.zcalib); 299 input_report_abs(lis3_dev.idev, ABS_Z, z - lis3_dev.zcalib);
290 300
291 input_sync(adev.idev); 301 input_sync(lis3_dev.idev);
292 302
293 try_to_freeze(); 303 try_to_freeze();
294 msleep_interruptible(MDPS_POLL_INTERVAL); 304 msleep_interruptible(MDPS_POLL_INTERVAL);
@@ -299,11 +309,11 @@ static int lis3lv02d_joystick_kthread(void *data)
299 309
300static int lis3lv02d_joystick_open(struct input_dev *input) 310static int lis3lv02d_joystick_open(struct input_dev *input)
301{ 311{
302 lis3lv02d_increase_use(&adev); 312 lis3lv02d_increase_use(&lis3_dev);
303 adev.kthread = kthread_run(lis3lv02d_joystick_kthread, NULL, "klis3lv02d"); 313 lis3_dev.kthread = kthread_run(lis3lv02d_joystick_kthread, NULL, "klis3lv02d");
304 if (IS_ERR(adev.kthread)) { 314 if (IS_ERR(lis3_dev.kthread)) {
305 lis3lv02d_decrease_use(&adev); 315 lis3lv02d_decrease_use(&lis3_dev);
306 return PTR_ERR(adev.kthread); 316 return PTR_ERR(lis3_dev.kthread);
307 } 317 }
308 318
309 return 0; 319 return 0;
@@ -311,45 +321,45 @@ static int lis3lv02d_joystick_open(struct input_dev *input)
311 321
312static void lis3lv02d_joystick_close(struct input_dev *input) 322static void lis3lv02d_joystick_close(struct input_dev *input)
313{ 323{
314 kthread_stop(adev.kthread); 324 kthread_stop(lis3_dev.kthread);
315 lis3lv02d_decrease_use(&adev); 325 lis3lv02d_decrease_use(&lis3_dev);
316} 326}
317 327
318static inline void lis3lv02d_calibrate_joystick(void) 328static inline void lis3lv02d_calibrate_joystick(void)
319{ 329{
320 lis3lv02d_get_xyz(adev.device->handle, &adev.xcalib, &adev.ycalib, &adev.zcalib); 330 lis3lv02d_get_xyz(lis3_dev.device->handle, &lis3_dev.xcalib, &lis3_dev.ycalib, &lis3_dev.zcalib);
321} 331}
322 332
323int lis3lv02d_joystick_enable(void) 333int lis3lv02d_joystick_enable(void)
324{ 334{
325 int err; 335 int err;
326 336
327 if (adev.idev) 337 if (lis3_dev.idev)
328 return -EINVAL; 338 return -EINVAL;
329 339
330 adev.idev = input_allocate_device(); 340 lis3_dev.idev = input_allocate_device();
331 if (!adev.idev) 341 if (!lis3_dev.idev)
332 return -ENOMEM; 342 return -ENOMEM;
333 343
334 lis3lv02d_calibrate_joystick(); 344 lis3lv02d_calibrate_joystick();
335 345
336 adev.idev->name = "ST LIS3LV02DL Accelerometer"; 346 lis3_dev.idev->name = "ST LIS3LV02DL Accelerometer";
337 adev.idev->phys = DRIVER_NAME "/input0"; 347 lis3_dev.idev->phys = DRIVER_NAME "/input0";
338 adev.idev->id.bustype = BUS_HOST; 348 lis3_dev.idev->id.bustype = BUS_HOST;
339 adev.idev->id.vendor = 0; 349 lis3_dev.idev->id.vendor = 0;
340 adev.idev->dev.parent = &adev.pdev->dev; 350 lis3_dev.idev->dev.parent = &lis3_dev.pdev->dev;
341 adev.idev->open = lis3lv02d_joystick_open; 351 lis3_dev.idev->open = lis3lv02d_joystick_open;
342 adev.idev->close = lis3lv02d_joystick_close; 352 lis3_dev.idev->close = lis3lv02d_joystick_close;
343 353
344 set_bit(EV_ABS, adev.idev->evbit); 354 set_bit(EV_ABS, lis3_dev.idev->evbit);
345 input_set_abs_params(adev.idev, ABS_X, -adev.mdps_max_val, adev.mdps_max_val, 3, 3); 355 input_set_abs_params(lis3_dev.idev, ABS_X, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
346 input_set_abs_params(adev.idev, ABS_Y, -adev.mdps_max_val, adev.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);
347 input_set_abs_params(adev.idev, ABS_Z, -adev.mdps_max_val, adev.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);
348 358
349 err = input_register_device(adev.idev); 359 err = input_register_device(lis3_dev.idev);
350 if (err) { 360 if (err) {
351 input_free_device(adev.idev); 361 input_free_device(lis3_dev.idev);
352 adev.idev = NULL; 362 lis3_dev.idev = NULL;
353 } 363 }
354 364
355 return err; 365 return err;
@@ -358,12 +368,12 @@ EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable);
358 368
359void lis3lv02d_joystick_disable(void) 369void lis3lv02d_joystick_disable(void)
360{ 370{
361 if (!adev.idev) 371 if (!lis3_dev.idev)
362 return; 372 return;
363 373
364 misc_deregister(&lis3lv02d_misc_device); 374 misc_deregister(&lis3lv02d_misc_device);
365 input_unregister_device(adev.idev); 375 input_unregister_device(lis3_dev.idev);
366 adev.idev = NULL; 376 lis3_dev.idev = NULL;
367} 377}
368EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable); 378EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);
369 379
@@ -404,25 +414,25 @@ static ssize_t lis3lv02d_position_show(struct device *dev,
404{ 414{
405 int x, y, z; 415 int x, y, z;
406 416
407 lis3lv02d_increase_use(&adev); 417 lis3lv02d_increase_use(&lis3_dev);
408 lis3lv02d_get_xyz(adev.device->handle, &x, &y, &z); 418 lis3lv02d_get_xyz(lis3_dev.device->handle, &x, &y, &z);
409 lis3lv02d_decrease_use(&adev); 419 lis3lv02d_decrease_use(&lis3_dev);
410 return sprintf(buf, "(%d,%d,%d)\n", x, y, z); 420 return sprintf(buf, "(%d,%d,%d)\n", x, y, z);
411} 421}
412 422
413static ssize_t lis3lv02d_calibrate_show(struct device *dev, 423static ssize_t lis3lv02d_calibrate_show(struct device *dev,
414 struct device_attribute *attr, char *buf) 424 struct device_attribute *attr, char *buf)
415{ 425{
416 return sprintf(buf, "(%d,%d,%d)\n", adev.xcalib, adev.ycalib, adev.zcalib); 426 return sprintf(buf, "(%d,%d,%d)\n", lis3_dev.xcalib, lis3_dev.ycalib, lis3_dev.zcalib);
417} 427}
418 428
419static ssize_t lis3lv02d_calibrate_store(struct device *dev, 429static ssize_t lis3lv02d_calibrate_store(struct device *dev,
420 struct device_attribute *attr, 430 struct device_attribute *attr,
421 const char *buf, size_t count) 431 const char *buf, size_t count)
422{ 432{
423 lis3lv02d_increase_use(&adev); 433 lis3lv02d_increase_use(&lis3_dev);
424 lis3lv02d_calibrate_joystick(); 434 lis3lv02d_calibrate_joystick();
425 lis3lv02d_decrease_use(&adev); 435 lis3lv02d_decrease_use(&lis3_dev);
426 return count; 436 return count;
427} 437}
428 438
@@ -434,9 +444,9 @@ static ssize_t lis3lv02d_rate_show(struct device *dev,
434 u8 ctrl; 444 u8 ctrl;
435 int val; 445 int val;
436 446
437 lis3lv02d_increase_use(&adev); 447 lis3lv02d_increase_use(&lis3_dev);
438 adev.read(adev.device->handle, CTRL_REG1, &ctrl); 448 lis3_dev.read(lis3_dev.device->handle, CTRL_REG1, &ctrl);
439 lis3lv02d_decrease_use(&adev); 449 lis3lv02d_decrease_use(&lis3_dev);
440 val = (ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4; 450 val = (ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4;
441 return sprintf(buf, "%d\n", lis3lv02dl_df_val[val]); 451 return sprintf(buf, "%d\n", lis3lv02dl_df_val[val]);
442} 452}
@@ -460,17 +470,17 @@ static struct attribute_group lis3lv02d_attribute_group = {
460 470
461static int lis3lv02d_add_fs(struct acpi_device *device) 471static int lis3lv02d_add_fs(struct acpi_device *device)
462{ 472{
463 adev.pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); 473 lis3_dev.pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
464 if (IS_ERR(adev.pdev)) 474 if (IS_ERR(lis3_dev.pdev))
465 return PTR_ERR(adev.pdev); 475 return PTR_ERR(lis3_dev.pdev);
466 476
467 return sysfs_create_group(&adev.pdev->dev.kobj, &lis3lv02d_attribute_group); 477 return sysfs_create_group(&lis3_dev.pdev->dev.kobj, &lis3lv02d_attribute_group);
468} 478}
469 479
470int lis3lv02d_remove_fs(void) 480int lis3lv02d_remove_fs(void)
471{ 481{
472 sysfs_remove_group(&adev.pdev->dev.kobj, &lis3lv02d_attribute_group); 482 sysfs_remove_group(&lis3_dev.pdev->dev.kobj, &lis3lv02d_attribute_group);
473 platform_device_unregister(adev.pdev); 483 platform_device_unregister(lis3_dev.pdev);
474 return 0; 484 return 0;
475} 485}
476EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs); 486EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs);