aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÉric Piel <eric.piel@tremplin-utc.net>2011-10-31 20:11:05 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-31 20:30:52 -0400
commit895c156c044a736d8dc2239020f4530bb6245675 (patch)
tree8da532a76d0081dde59e89142503e0ee5b82dec3
parente1e5687d75ef0ea5cbae63df48ff2fdcb5306f66 (diff)
lis3: remove the references to the global variable in core driver
[ilkka.koskinen@nokia.com: fix arg to lis3->read()] Signed-off-by: Ilkka Koskinen <ilkka.koskinen@nokia.com> Signed-off-by: Éric Piel <eric.piel@tremplin-utc.net> Cc: Matthew Garrett <mjg@redhat.com> Cc: Witold Pilat <witold.pilat@gmail.com> Cc: Lyall Pearce <lyall.pearce@hp.com> Cc: Malte Starostik <m-starostik@versanet.de> Cc: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com> Cc: Christian Lamparter <chunkeey@googlemail.com> Subject: lis3-remove-the-references-to-the-global-variable-in-core-driver-fix Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/misc/lis3lv02d/lis3lv02d.c233
-rw-r--r--drivers/misc/lis3lv02d/lis3lv02d.h3
2 files changed, 133 insertions, 103 deletions
diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
index 57249a01e6e7..29d12a70eb1b 100644
--- a/drivers/misc/lis3lv02d/lis3lv02d.c
+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
@@ -163,7 +163,7 @@ static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z)
163 int i; 163 int i;
164 164
165 if (lis3->blkread) { 165 if (lis3->blkread) {
166 if (lis3_dev.whoami == WAI_12B) { 166 if (lis3->whoami == WAI_12B) {
167 u16 data[3]; 167 u16 data[3];
168 lis3->blkread(lis3, OUTX_L, 6, (u8 *)data); 168 lis3->blkread(lis3, OUTX_L, 6, (u8 *)data);
169 for (i = 0; i < 3; i++) 169 for (i = 0; i < 3; i++)
@@ -195,20 +195,20 @@ static int lis3_8_rates[2] = {100, 400};
195static int lis3_3dc_rates[16] = {0, 1, 10, 25, 50, 100, 200, 400, 1600, 5000}; 195static int lis3_3dc_rates[16] = {0, 1, 10, 25, 50, 100, 200, 400, 1600, 5000};
196 196
197/* ODR is Output Data Rate */ 197/* ODR is Output Data Rate */
198static int lis3lv02d_get_odr(void) 198static int lis3lv02d_get_odr(struct lis3lv02d *lis3)
199{ 199{
200 u8 ctrl; 200 u8 ctrl;
201 int shift; 201 int shift;
202 202
203 lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl); 203 lis3->read(lis3, CTRL_REG1, &ctrl);
204 ctrl &= lis3_dev.odr_mask; 204 ctrl &= lis3->odr_mask;
205 shift = ffs(lis3_dev.odr_mask) - 1; 205 shift = ffs(lis3->odr_mask) - 1;
206 return lis3_dev.odrs[(ctrl >> shift)]; 206 return lis3->odrs[(ctrl >> shift)];
207} 207}
208 208
209static int lis3lv02d_get_pwron_wait(struct lis3lv02d *lis3) 209static int lis3lv02d_get_pwron_wait(struct lis3lv02d *lis3)
210{ 210{
211 int div = lis3lv02d_get_odr(); 211 int div = lis3lv02d_get_odr(lis3);
212 212
213 if (WARN_ONCE(div == 0, "device returned spurious data")) 213 if (WARN_ONCE(div == 0, "device returned spurious data"))
214 return -ENXIO; 214 return -ENXIO;
@@ -218,7 +218,7 @@ static int lis3lv02d_get_pwron_wait(struct lis3lv02d *lis3)
218 return 0; 218 return 0;
219} 219}
220 220
221static int lis3lv02d_set_odr(int rate) 221static int lis3lv02d_set_odr(struct lis3lv02d *lis3, int rate)
222{ 222{
223 u8 ctrl; 223 u8 ctrl;
224 int i, len, shift; 224 int i, len, shift;
@@ -226,14 +226,14 @@ static int lis3lv02d_set_odr(int rate)
226 if (!rate) 226 if (!rate)
227 return -EINVAL; 227 return -EINVAL;
228 228
229 lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl); 229 lis3->read(lis3, CTRL_REG1, &ctrl);
230 ctrl &= ~lis3_dev.odr_mask; 230 ctrl &= ~lis3->odr_mask;
231 len = 1 << hweight_long(lis3_dev.odr_mask); /* # of possible values */ 231 len = 1 << hweight_long(lis3->odr_mask); /* # of possible values */
232 shift = ffs(lis3_dev.odr_mask) - 1; 232 shift = ffs(lis3->odr_mask) - 1;
233 233
234 for (i = 0; i < len; i++) 234 for (i = 0; i < len; i++)
235 if (lis3_dev.odrs[i] == rate) { 235 if (lis3->odrs[i] == rate) {
236 lis3_dev.write(&lis3_dev, CTRL_REG1, 236 lis3->write(lis3, CTRL_REG1,
237 ctrl | (i << shift)); 237 ctrl | (i << shift));
238 return 0; 238 return 0;
239 } 239 }
@@ -252,12 +252,12 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
252 mutex_lock(&lis3->mutex); 252 mutex_lock(&lis3->mutex);
253 253
254 irq_cfg = lis3->irq_cfg; 254 irq_cfg = lis3->irq_cfg;
255 if (lis3_dev.whoami == WAI_8B) { 255 if (lis3->whoami == WAI_8B) {
256 lis3->data_ready_count[IRQ_LINE0] = 0; 256 lis3->data_ready_count[IRQ_LINE0] = 0;
257 lis3->data_ready_count[IRQ_LINE1] = 0; 257 lis3->data_ready_count[IRQ_LINE1] = 0;
258 258
259 /* Change interrupt cfg to data ready for selftest */ 259 /* Change interrupt cfg to data ready for selftest */
260 atomic_inc(&lis3_dev.wake_thread); 260 atomic_inc(&lis3->wake_thread);
261 lis3->irq_cfg = LIS3_IRQ1_DATA_READY | LIS3_IRQ2_DATA_READY; 261 lis3->irq_cfg = LIS3_IRQ1_DATA_READY | LIS3_IRQ2_DATA_READY;
262 lis3->read(lis3, CTRL_REG3, &ctrl_reg_data); 262 lis3->read(lis3, CTRL_REG3, &ctrl_reg_data);
263 lis3->write(lis3, CTRL_REG3, (ctrl_reg_data & 263 lis3->write(lis3, CTRL_REG3, (ctrl_reg_data &
@@ -265,12 +265,12 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
265 (LIS3_IRQ1_DATA_READY | LIS3_IRQ2_DATA_READY)); 265 (LIS3_IRQ1_DATA_READY | LIS3_IRQ2_DATA_READY));
266 } 266 }
267 267
268 if (lis3_dev.whoami == WAI_3DC) { 268 if (lis3->whoami == WAI_3DC) {
269 ctlreg = CTRL_REG4; 269 ctlreg = CTRL_REG4;
270 selftest = CTRL4_ST0; 270 selftest = CTRL4_ST0;
271 } else { 271 } else {
272 ctlreg = CTRL_REG1; 272 ctlreg = CTRL_REG1;
273 if (lis3_dev.whoami == WAI_12B) 273 if (lis3->whoami == WAI_12B)
274 selftest = CTRL1_ST; 274 selftest = CTRL1_ST;
275 else 275 else
276 selftest = CTRL1_STP; 276 selftest = CTRL1_STP;
@@ -299,9 +299,9 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
299 299
300 ret = 0; 300 ret = 0;
301 301
302 if (lis3_dev.whoami == WAI_8B) { 302 if (lis3->whoami == WAI_8B) {
303 /* Restore original interrupt configuration */ 303 /* Restore original interrupt configuration */
304 atomic_dec(&lis3_dev.wake_thread); 304 atomic_dec(&lis3->wake_thread);
305 lis3->write(lis3, CTRL_REG3, ctrl_reg_data); 305 lis3->write(lis3, CTRL_REG3, ctrl_reg_data);
306 lis3->irq_cfg = irq_cfg; 306 lis3->irq_cfg = irq_cfg;
307 307
@@ -415,24 +415,27 @@ EXPORT_SYMBOL_GPL(lis3lv02d_poweron);
415 415
416static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev) 416static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev)
417{ 417{
418 struct lis3lv02d *lis3 = pidev->private;
418 int x, y, z; 419 int x, y, z;
419 420
420 mutex_lock(&lis3_dev.mutex); 421 mutex_lock(&lis3->mutex);
421 lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); 422 lis3lv02d_get_xyz(lis3, &x, &y, &z);
422 input_report_abs(pidev->input, ABS_X, x); 423 input_report_abs(pidev->input, ABS_X, x);
423 input_report_abs(pidev->input, ABS_Y, y); 424 input_report_abs(pidev->input, ABS_Y, y);
424 input_report_abs(pidev->input, ABS_Z, z); 425 input_report_abs(pidev->input, ABS_Z, z);
425 input_sync(pidev->input); 426 input_sync(pidev->input);
426 mutex_unlock(&lis3_dev.mutex); 427 mutex_unlock(&lis3->mutex);
427} 428}
428 429
429static void lis3lv02d_joystick_open(struct input_polled_dev *pidev) 430static void lis3lv02d_joystick_open(struct input_polled_dev *pidev)
430{ 431{
431 if (lis3_dev.pm_dev) 432 struct lis3lv02d *lis3 = pidev->private;
432 pm_runtime_get_sync(lis3_dev.pm_dev);
433 433
434 if (lis3_dev.pdata && lis3_dev.whoami == WAI_8B && lis3_dev.idev) 434 if (lis3->pm_dev)
435 atomic_set(&lis3_dev.wake_thread, 1); 435 pm_runtime_get_sync(lis3->pm_dev);
436
437 if (lis3->pdata && lis3->whoami == WAI_8B && lis3->idev)
438 atomic_set(&lis3->wake_thread, 1);
436 /* 439 /*
437 * Update coordinates for the case where poll interval is 0 and 440 * Update coordinates for the case where poll interval is 0 and
438 * the chip in running purely under interrupt control 441 * the chip in running purely under interrupt control
@@ -442,14 +445,18 @@ static void lis3lv02d_joystick_open(struct input_polled_dev *pidev)
442 445
443static void lis3lv02d_joystick_close(struct input_polled_dev *pidev) 446static void lis3lv02d_joystick_close(struct input_polled_dev *pidev)
444{ 447{
445 atomic_set(&lis3_dev.wake_thread, 0); 448 struct lis3lv02d *lis3 = pidev->private;
446 if (lis3_dev.pm_dev) 449
447 pm_runtime_put(lis3_dev.pm_dev); 450 atomic_set(&lis3->wake_thread, 0);
451 if (lis3->pm_dev)
452 pm_runtime_put(lis3->pm_dev);
448} 453}
449 454
450static irqreturn_t lis302dl_interrupt(int irq, void *dummy) 455static irqreturn_t lis302dl_interrupt(int irq, void *data)
451{ 456{
452 if (!test_bit(0, &lis3_dev.misc_opened)) 457 struct lis3lv02d *lis3 = data;
458
459 if (!test_bit(0, &lis3->misc_opened))
453 goto out; 460 goto out;
454 461
455 /* 462 /*
@@ -457,12 +464,12 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
457 * the lid is closed. This leads to interrupts as soon as a little move 464 * the lid is closed. This leads to interrupts as soon as a little move
458 * is done. 465 * is done.
459 */ 466 */
460 atomic_inc(&lis3_dev.count); 467 atomic_inc(&lis3->count);
461 468
462 wake_up_interruptible(&lis3_dev.misc_wait); 469 wake_up_interruptible(&lis3->misc_wait);
463 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN); 470 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
464out: 471out:
465 if (atomic_read(&lis3_dev.wake_thread)) 472 if (atomic_read(&lis3->wake_thread))
466 return IRQ_WAKE_THREAD; 473 return IRQ_WAKE_THREAD;
467 return IRQ_HANDLED; 474 return IRQ_HANDLED;
468} 475}
@@ -534,28 +541,37 @@ static irqreturn_t lis302dl_interrupt_thread2_8b(int irq, void *data)
534 541
535static int lis3lv02d_misc_open(struct inode *inode, struct file *file) 542static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
536{ 543{
537 if (test_and_set_bit(0, &lis3_dev.misc_opened)) 544 struct lis3lv02d *lis3 = container_of(file->private_data,
545 struct lis3lv02d, miscdev);
546
547 if (test_and_set_bit(0, &lis3->misc_opened))
538 return -EBUSY; /* already open */ 548 return -EBUSY; /* already open */
539 549
540 if (lis3_dev.pm_dev) 550 if (lis3->pm_dev)
541 pm_runtime_get_sync(lis3_dev.pm_dev); 551 pm_runtime_get_sync(lis3->pm_dev);
542 552
543 atomic_set(&lis3_dev.count, 0); 553 atomic_set(&lis3->count, 0);
544 return 0; 554 return 0;
545} 555}
546 556
547static int lis3lv02d_misc_release(struct inode *inode, struct file *file) 557static int lis3lv02d_misc_release(struct inode *inode, struct file *file)
548{ 558{
549 fasync_helper(-1, file, 0, &lis3_dev.async_queue); 559 struct lis3lv02d *lis3 = container_of(file->private_data,
550 clear_bit(0, &lis3_dev.misc_opened); /* release the device */ 560 struct lis3lv02d, miscdev);
551 if (lis3_dev.pm_dev) 561
552 pm_runtime_put(lis3_dev.pm_dev); 562 fasync_helper(-1, file, 0, &lis3->async_queue);
563 clear_bit(0, &lis3->misc_opened); /* release the device */
564 if (lis3->pm_dev)
565 pm_runtime_put(lis3->pm_dev);
553 return 0; 566 return 0;
554} 567}
555 568
556static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf, 569static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
557 size_t count, loff_t *pos) 570 size_t count, loff_t *pos)
558{ 571{
572 struct lis3lv02d *lis3 = container_of(file->private_data,
573 struct lis3lv02d, miscdev);
574
559 DECLARE_WAITQUEUE(wait, current); 575 DECLARE_WAITQUEUE(wait, current);
560 u32 data; 576 u32 data;
561 unsigned char byte_data; 577 unsigned char byte_data;
@@ -564,10 +580,10 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
564 if (count < 1) 580 if (count < 1)
565 return -EINVAL; 581 return -EINVAL;
566 582
567 add_wait_queue(&lis3_dev.misc_wait, &wait); 583 add_wait_queue(&lis3->misc_wait, &wait);
568 while (true) { 584 while (true) {
569 set_current_state(TASK_INTERRUPTIBLE); 585 set_current_state(TASK_INTERRUPTIBLE);
570 data = atomic_xchg(&lis3_dev.count, 0); 586 data = atomic_xchg(&lis3->count, 0);
571 if (data) 587 if (data)
572 break; 588 break;
573 589
@@ -597,22 +613,28 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
597 613
598out: 614out:
599 __set_current_state(TASK_RUNNING); 615 __set_current_state(TASK_RUNNING);
600 remove_wait_queue(&lis3_dev.misc_wait, &wait); 616 remove_wait_queue(&lis3->misc_wait, &wait);
601 617
602 return retval; 618 return retval;
603} 619}
604 620
605static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait) 621static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
606{ 622{
607 poll_wait(file, &lis3_dev.misc_wait, wait); 623 struct lis3lv02d *lis3 = container_of(file->private_data,
608 if (atomic_read(&lis3_dev.count)) 624 struct lis3lv02d, miscdev);
625
626 poll_wait(file, &lis3->misc_wait, wait);
627 if (atomic_read(&lis3->count))
609 return POLLIN | POLLRDNORM; 628 return POLLIN | POLLRDNORM;
610 return 0; 629 return 0;
611} 630}
612 631
613static int lis3lv02d_misc_fasync(int fd, struct file *file, int on) 632static int lis3lv02d_misc_fasync(int fd, struct file *file, int on)
614{ 633{
615 return fasync_helper(fd, file, on, &lis3_dev.async_queue); 634 struct lis3lv02d *lis3 = container_of(file->private_data,
635 struct lis3lv02d, miscdev);
636
637 return fasync_helper(fd, file, on, &lis3->async_queue);
616} 638}
617 639
618static const struct file_operations lis3lv02d_misc_fops = { 640static const struct file_operations lis3lv02d_misc_fops = {
@@ -625,12 +647,6 @@ static const struct file_operations lis3lv02d_misc_fops = {
625 .fasync = lis3lv02d_misc_fasync, 647 .fasync = lis3lv02d_misc_fasync,
626}; 648};
627 649
628static struct miscdevice lis3lv02d_misc_device = {
629 .minor = MISC_DYNAMIC_MINOR,
630 .name = "freefall",
631 .fops = &lis3lv02d_misc_fops,
632};
633
634int lis3lv02d_joystick_enable(struct lis3lv02d *lis3) 650int lis3lv02d_joystick_enable(struct lis3lv02d *lis3)
635{ 651{
636 struct input_dev *input_dev; 652 struct input_dev *input_dev;
@@ -638,51 +654,52 @@ int lis3lv02d_joystick_enable(struct lis3lv02d *lis3)
638 int max_val, fuzz, flat; 654 int max_val, fuzz, flat;
639 int btns[] = {BTN_X, BTN_Y, BTN_Z}; 655 int btns[] = {BTN_X, BTN_Y, BTN_Z};
640 656
641 if (lis3_dev.idev) 657 if (lis3->idev)
642 return -EINVAL; 658 return -EINVAL;
643 659
644 lis3_dev.idev = input_allocate_polled_device(); 660 lis3->idev = input_allocate_polled_device();
645 if (!lis3_dev.idev) 661 if (!lis3->idev)
646 return -ENOMEM; 662 return -ENOMEM;
647 663
648 lis3_dev.idev->poll = lis3lv02d_joystick_poll; 664 lis3->idev->poll = lis3lv02d_joystick_poll;
649 lis3_dev.idev->open = lis3lv02d_joystick_open; 665 lis3->idev->open = lis3lv02d_joystick_open;
650 lis3_dev.idev->close = lis3lv02d_joystick_close; 666 lis3->idev->close = lis3lv02d_joystick_close;
651 lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL; 667 lis3->idev->poll_interval = MDPS_POLL_INTERVAL;
652 lis3_dev.idev->poll_interval_min = MDPS_POLL_MIN; 668 lis3->idev->poll_interval_min = MDPS_POLL_MIN;
653 lis3_dev.idev->poll_interval_max = MDPS_POLL_MAX; 669 lis3->idev->poll_interval_max = MDPS_POLL_MAX;
654 input_dev = lis3_dev.idev->input; 670 lis3->idev->private = lis3;
671 input_dev = lis3->idev->input;
655 672
656 input_dev->name = "ST LIS3LV02DL Accelerometer"; 673 input_dev->name = "ST LIS3LV02DL Accelerometer";
657 input_dev->phys = DRIVER_NAME "/input0"; 674 input_dev->phys = DRIVER_NAME "/input0";
658 input_dev->id.bustype = BUS_HOST; 675 input_dev->id.bustype = BUS_HOST;
659 input_dev->id.vendor = 0; 676 input_dev->id.vendor = 0;
660 input_dev->dev.parent = &lis3_dev.pdev->dev; 677 input_dev->dev.parent = &lis3->pdev->dev;
661 678
662 set_bit(EV_ABS, input_dev->evbit); 679 set_bit(EV_ABS, input_dev->evbit);
663 max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY; 680 max_val = (lis3->mdps_max_val * lis3->scale) / LIS3_ACCURACY;
664 if (lis3_dev.whoami == WAI_12B) { 681 if (lis3->whoami == WAI_12B) {
665 fuzz = LIS3_DEFAULT_FUZZ_12B; 682 fuzz = LIS3_DEFAULT_FUZZ_12B;
666 flat = LIS3_DEFAULT_FLAT_12B; 683 flat = LIS3_DEFAULT_FLAT_12B;
667 } else { 684 } else {
668 fuzz = LIS3_DEFAULT_FUZZ_8B; 685 fuzz = LIS3_DEFAULT_FUZZ_8B;
669 flat = LIS3_DEFAULT_FLAT_8B; 686 flat = LIS3_DEFAULT_FLAT_8B;
670 } 687 }
671 fuzz = (fuzz * lis3_dev.scale) / LIS3_ACCURACY; 688 fuzz = (fuzz * lis3->scale) / LIS3_ACCURACY;
672 flat = (flat * lis3_dev.scale) / LIS3_ACCURACY; 689 flat = (flat * lis3->scale) / LIS3_ACCURACY;
673 690
674 input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat); 691 input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat);
675 input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat); 692 input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat);
676 input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat); 693 input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat);
677 694
678 lis3_dev.mapped_btns[0] = lis3lv02d_get_axis(abs(lis3_dev.ac.x), btns); 695 lis3->mapped_btns[0] = lis3lv02d_get_axis(abs(lis3->ac.x), btns);
679 lis3_dev.mapped_btns[1] = lis3lv02d_get_axis(abs(lis3_dev.ac.y), btns); 696 lis3->mapped_btns[1] = lis3lv02d_get_axis(abs(lis3->ac.y), btns);
680 lis3_dev.mapped_btns[2] = lis3lv02d_get_axis(abs(lis3_dev.ac.z), btns); 697 lis3->mapped_btns[2] = lis3lv02d_get_axis(abs(lis3->ac.z), btns);
681 698
682 err = input_register_polled_device(lis3_dev.idev); 699 err = input_register_polled_device(lis3->idev);
683 if (err) { 700 if (err) {
684 input_free_polled_device(lis3_dev.idev); 701 input_free_polled_device(lis3->idev);
685 lis3_dev.idev = NULL; 702 lis3->idev = NULL;
686 } 703 }
687 704
688 return err; 705 return err;
@@ -691,19 +708,19 @@ EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable);
691 708
692void lis3lv02d_joystick_disable(struct lis3lv02d *lis3) 709void lis3lv02d_joystick_disable(struct lis3lv02d *lis3)
693{ 710{
694 if (lis3_dev.irq) 711 if (lis3->irq)
695 free_irq(lis3_dev.irq, &lis3_dev); 712 free_irq(lis3->irq, lis3);
696 if (lis3_dev.pdata && lis3_dev.pdata->irq2) 713 if (lis3->pdata && lis3->pdata->irq2)
697 free_irq(lis3_dev.pdata->irq2, &lis3_dev); 714 free_irq(lis3->pdata->irq2, lis3);
698 715
699 if (!lis3_dev.idev) 716 if (!lis3->idev)
700 return; 717 return;
701 718
702 if (lis3_dev.irq) 719 if (lis3->irq)
703 misc_deregister(&lis3lv02d_misc_device); 720 misc_deregister(&lis3->miscdev);
704 input_unregister_polled_device(lis3_dev.idev); 721 input_unregister_polled_device(lis3->idev);
705 input_free_polled_device(lis3_dev.idev); 722 input_free_polled_device(lis3->idev);
706 lis3_dev.idev = NULL; 723 lis3->idev = NULL;
707} 724}
708EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable); 725EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);
709 726
@@ -728,6 +745,7 @@ static void lis3lv02d_sysfs_poweron(struct lis3lv02d *lis3)
728static ssize_t lis3lv02d_selftest_show(struct device *dev, 745static ssize_t lis3lv02d_selftest_show(struct device *dev,
729 struct device_attribute *attr, char *buf) 746 struct device_attribute *attr, char *buf)
730{ 747{
748 struct lis3lv02d *lis3 = dev_get_drvdata(dev);
731 s16 values[3]; 749 s16 values[3];
732 750
733 static const char ok[] = "OK"; 751 static const char ok[] = "OK";
@@ -735,8 +753,8 @@ static ssize_t lis3lv02d_selftest_show(struct device *dev,
735 static const char irq[] = "FAIL_IRQ"; 753 static const char irq[] = "FAIL_IRQ";
736 const char *res; 754 const char *res;
737 755
738 lis3lv02d_sysfs_poweron(&lis3_dev); 756 lis3lv02d_sysfs_poweron(lis3);
739 switch (lis3lv02d_selftest(&lis3_dev, values)) { 757 switch (lis3lv02d_selftest(lis3, values)) {
740 case SELFTEST_FAIL: 758 case SELFTEST_FAIL:
741 res = fail; 759 res = fail;
742 break; 760 break;
@@ -755,33 +773,37 @@ static ssize_t lis3lv02d_selftest_show(struct device *dev,
755static ssize_t lis3lv02d_position_show(struct device *dev, 773static ssize_t lis3lv02d_position_show(struct device *dev,
756 struct device_attribute *attr, char *buf) 774 struct device_attribute *attr, char *buf)
757{ 775{
776 struct lis3lv02d *lis3 = dev_get_drvdata(dev);
758 int x, y, z; 777 int x, y, z;
759 778
760 lis3lv02d_sysfs_poweron(&lis3_dev); 779 lis3lv02d_sysfs_poweron(lis3);
761 mutex_lock(&lis3_dev.mutex); 780 mutex_lock(&lis3->mutex);
762 lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); 781 lis3lv02d_get_xyz(lis3, &x, &y, &z);
763 mutex_unlock(&lis3_dev.mutex); 782 mutex_unlock(&lis3->mutex);
764 return sprintf(buf, "(%d,%d,%d)\n", x, y, z); 783 return sprintf(buf, "(%d,%d,%d)\n", x, y, z);
765} 784}
766 785
767static ssize_t lis3lv02d_rate_show(struct device *dev, 786static ssize_t lis3lv02d_rate_show(struct device *dev,
768 struct device_attribute *attr, char *buf) 787 struct device_attribute *attr, char *buf)
769{ 788{
770 lis3lv02d_sysfs_poweron(&lis3_dev); 789 struct lis3lv02d *lis3 = dev_get_drvdata(dev);
771 return sprintf(buf, "%d\n", lis3lv02d_get_odr()); 790
791 lis3lv02d_sysfs_poweron(lis3);
792 return sprintf(buf, "%d\n", lis3lv02d_get_odr(lis3));
772} 793}
773 794
774static ssize_t lis3lv02d_rate_set(struct device *dev, 795static ssize_t lis3lv02d_rate_set(struct device *dev,
775 struct device_attribute *attr, const char *buf, 796 struct device_attribute *attr, const char *buf,
776 size_t count) 797 size_t count)
777{ 798{
799 struct lis3lv02d *lis3 = dev_get_drvdata(dev);
778 unsigned long rate; 800 unsigned long rate;
779 801
780 if (strict_strtoul(buf, 0, &rate)) 802 if (strict_strtoul(buf, 0, &rate))
781 return -EINVAL; 803 return -EINVAL;
782 804
783 lis3lv02d_sysfs_poweron(&lis3_dev); 805 lis3lv02d_sysfs_poweron(lis3);
784 if (lis3lv02d_set_odr(rate)) 806 if (lis3lv02d_set_odr(lis3, rate))
785 return -EINVAL; 807 return -EINVAL;
786 808
787 return count; 809 return count;
@@ -810,6 +832,7 @@ static int lis3lv02d_add_fs(struct lis3lv02d *lis3)
810 if (IS_ERR(lis3->pdev)) 832 if (IS_ERR(lis3->pdev))
811 return PTR_ERR(lis3->pdev); 833 return PTR_ERR(lis3->pdev);
812 834
835 platform_set_drvdata(lis3->pdev, lis3);
813 return sysfs_create_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group); 836 return sysfs_create_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group);
814} 837}
815 838
@@ -823,7 +846,7 @@ int lis3lv02d_remove_fs(struct lis3lv02d *lis3)
823 846
824 /* SYSFS may have left chip running. Turn off if necessary */ 847 /* SYSFS may have left chip running. Turn off if necessary */
825 if (!pm_runtime_suspended(lis3->pm_dev)) 848 if (!pm_runtime_suspended(lis3->pm_dev))
826 lis3lv02d_poweroff(&lis3_dev); 849 lis3lv02d_poweroff(lis3);
827 850
828 pm_runtime_disable(lis3->pm_dev); 851 pm_runtime_disable(lis3->pm_dev);
829 pm_runtime_set_suspended(lis3->pm_dev); 852 pm_runtime_set_suspended(lis3->pm_dev);
@@ -850,7 +873,7 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *lis3,
850 (p->click_thresh_y << 4)); 873 (p->click_thresh_y << 4));
851 874
852 if (lis3->idev) { 875 if (lis3->idev) {
853 struct input_dev *input_dev = lis3_dev.idev->input; 876 struct input_dev *input_dev = lis3->idev->input;
854 input_set_capability(input_dev, EV_KEY, BTN_X); 877 input_set_capability(input_dev, EV_KEY, BTN_X);
855 input_set_capability(input_dev, EV_KEY, BTN_Y); 878 input_set_capability(input_dev, EV_KEY, BTN_Y);
856 input_set_capability(input_dev, EV_KEY, BTN_Z); 879 input_set_capability(input_dev, EV_KEY, BTN_Z);
@@ -881,7 +904,7 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *lis3,
881 lis302dl_interrupt_thread2_8b, 904 lis302dl_interrupt_thread2_8b,
882 IRQF_TRIGGER_RISING | IRQF_ONESHOT | 905 IRQF_TRIGGER_RISING | IRQF_ONESHOT |
883 (p->irq_flags2 & IRQF_TRIGGER_MASK), 906 (p->irq_flags2 & IRQF_TRIGGER_MASK),
884 DRIVER_NAME, &lis3_dev); 907 DRIVER_NAME, lis3);
885 if (err < 0) 908 if (err < 0)
886 pr_err("No second IRQ. Limited functionality\n"); 909 pr_err("No second IRQ. Limited functionality\n");
887 } 910 }
@@ -977,7 +1000,7 @@ int lis3lv02d_init_device(struct lis3lv02d *lis3)
977 lis3->write(lis3, CTRL_REG3, p->irq_cfg); 1000 lis3->write(lis3, CTRL_REG3, p->irq_cfg);
978 1001
979 if (p->default_rate) 1002 if (p->default_rate)
980 lis3lv02d_set_odr(p->default_rate); 1003 lis3lv02d_set_odr(lis3, p->default_rate);
981 } 1004 }
982 1005
983 /* bail if we did not get an IRQ from the bus layer */ 1006 /* bail if we did not get an IRQ from the bus layer */
@@ -1006,14 +1029,18 @@ int lis3lv02d_init_device(struct lis3lv02d *lis3)
1006 thread_fn, 1029 thread_fn,
1007 IRQF_TRIGGER_RISING | IRQF_ONESHOT | 1030 IRQF_TRIGGER_RISING | IRQF_ONESHOT |
1008 irq_flags, 1031 irq_flags,
1009 DRIVER_NAME, &lis3_dev); 1032 DRIVER_NAME, lis3);
1010 1033
1011 if (err < 0) { 1034 if (err < 0) {
1012 pr_err("Cannot get IRQ\n"); 1035 pr_err("Cannot get IRQ\n");
1013 goto out; 1036 goto out;
1014 } 1037 }
1015 1038
1016 if (misc_register(&lis3lv02d_misc_device)) 1039 lis3->miscdev.minor = MISC_DYNAMIC_MINOR;
1040 lis3->miscdev.name = "freefall";
1041 lis3->miscdev.fops = &lis3lv02d_misc_fops;
1042
1043 if (misc_register(&lis3->miscdev))
1017 pr_err("misc_register failed\n"); 1044 pr_err("misc_register failed\n");
1018out: 1045out:
1019 return 0; 1046 return 0;
diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
index b94e72374810..2b1482ad3f16 100644
--- a/drivers/misc/lis3lv02d/lis3lv02d.h
+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
@@ -21,6 +21,7 @@
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/input-polldev.h> 22#include <linux/input-polldev.h>
23#include <linux/regulator/consumer.h> 23#include <linux/regulator/consumer.h>
24#include <linux/miscdevice.h>
24 25
25/* 26/*
26 * This driver tries to support the "digital" accelerometer chips from 27 * This driver tries to support the "digital" accelerometer chips from
@@ -273,6 +274,8 @@ struct lis3lv02d {
273 struct fasync_struct *async_queue; /* queue for the misc device */ 274 struct fasync_struct *async_queue; /* queue for the misc device */
274 wait_queue_head_t misc_wait; /* Wait queue for the misc device */ 275 wait_queue_head_t misc_wait; /* Wait queue for the misc device */
275 unsigned long misc_opened; /* bit0: whether the device is open */ 276 unsigned long misc_opened; /* bit0: whether the device is open */
277 struct miscdevice miscdev;
278
276 int data_ready_count[2]; 279 int data_ready_count[2];
277 atomic_t wake_thread; 280 atomic_t wake_thread;
278 unsigned char irq_cfg; 281 unsigned char irq_cfg;