diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-01 01:46:07 +0100 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-01 01:46:07 +0100 |
commit | 094803e0aab3fe75bbf8202a8f4b5280eaade375 (patch) | |
tree | 278528ca9245a767fcfcfa97d977bd5714c082fd /drivers/misc | |
parent | Merge branch 'for-linus' of git://git390.marist.edu/pub/scm/linux-2.6 (diff) | |
parent | epoll: fix spurious lockdep warnings (diff) | |
download | linux-094803e0aab3fe75bbf8202a8f4b5280eaade375.tar.xz linux-094803e0aab3fe75bbf8202a8f4b5280eaade375.zip |
Merge branch 'akpm' (Andrew's incoming)
Quoth Andrew:
- Most of MM. Still waiting for the poweroc guys to get off their
butts and review some threaded hugepages patches.
- alpha
- vfs bits
- drivers/misc
- a few core kerenl tweaks
- printk() features
- MAINTAINERS updates
- backlight merge
- leds merge
- various lib/ updates
- checkpatch updates
* akpm: (127 commits)
epoll: fix spurious lockdep warnings
checkpatch: add a --strict check for utf-8 in commit logs
kernel.h/checkpatch: mark strict_strto<foo> and simple_strto<foo> as obsolete
llist-return-whether-list-is-empty-before-adding-in-llist_add-fix
wireless: at76c50x: follow rename pack_hex_byte to hex_byte_pack
fat: follow rename pack_hex_byte() to hex_byte_pack()
security: follow rename pack_hex_byte() to hex_byte_pack()
kgdb: follow rename pack_hex_byte() to hex_byte_pack()
lib: rename pack_hex_byte() to hex_byte_pack()
lib/string.c: fix strim() semantics for strings that have only blanks
lib/idr.c: fix comment for ida_get_new_above()
lib/percpu_counter.c: enclose hotplug only variables in hotplug ifdef
lib/bitmap.c: quiet sparse noise about address space
lib/spinlock_debug.c: print owner on spinlock lockup
lib/kstrtox: common code between kstrto*() and simple_strto*() functions
drivers/leds/leds-lp5521.c: check if reset is successful
leds: turn the blink_timer off before starting to blink
leds: save the delay values after a successful call to blink_set()
drivers/leds/leds-gpio.c: use gpio_get_value_cansleep() when initializing
drivers/leds/leds-lm3530.c: add __devexit_p where needed
...
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/ad525x_dpot-i2c.c | 1 | ||||
-rw-r--r-- | drivers/misc/fsa9480.c | 3 | ||||
-rw-r--r-- | drivers/misc/lis3lv02d/lis3lv02d.c | 389 | ||||
-rw-r--r-- | drivers/misc/lis3lv02d/lis3lv02d.h | 9 | ||||
-rw-r--r-- | drivers/misc/lis3lv02d/lis3lv02d_i2c.c | 45 | ||||
-rw-r--r-- | drivers/misc/lis3lv02d/lis3lv02d_spi.c | 2 |
6 files changed, 250 insertions, 199 deletions
diff --git a/drivers/misc/ad525x_dpot-i2c.c b/drivers/misc/ad525x_dpot-i2c.c index 4ff73c215746..a39e0555df63 100644 --- a/drivers/misc/ad525x_dpot-i2c.c +++ b/drivers/misc/ad525x_dpot-i2c.c @@ -98,6 +98,7 @@ static const struct i2c_device_id ad_dpot_id[] = { {"ad5282", AD5282_ID}, {"adn2860", ADN2860_ID}, {"ad5273", AD5273_ID}, + {"ad5161", AD5161_ID}, {"ad5171", AD5171_ID}, {"ad5170", AD5170_ID}, {"ad5172", AD5172_ID}, diff --git a/drivers/misc/fsa9480.c b/drivers/misc/fsa9480.c index 27dc0d21aafa..f6586d53e1a3 100644 --- a/drivers/misc/fsa9480.c +++ b/drivers/misc/fsa9480.c @@ -400,7 +400,8 @@ static int fsa9480_irq_init(struct fsa9480_usbsw *usbsw) return ret; } - device_init_wakeup(&client->dev, pdata->wakeup); + if (pdata) + device_init_wakeup(&client->dev, pdata->wakeup); } return 0; diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c index 8b51cd62d067..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) int i; if (lis3->blkread) { - if (lis3_dev.whoami == WAI_12B) { + if (lis3->whoami == WAI_12B) { u16 data[3]; lis3->blkread(lis3, OUTX_L, 6, (u8 *)data); for (i = 0; i < 3; i++) @@ -195,18 +195,30 @@ static int lis3_8_rates[2] = {100, 400}; static int lis3_3dc_rates[16] = {0, 1, 10, 25, 50, 100, 200, 400, 1600, 5000}; /* ODR is Output Data Rate */ -static int lis3lv02d_get_odr(void) +static int lis3lv02d_get_odr(struct lis3lv02d *lis3) { u8 ctrl; int shift; - lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl); - ctrl &= lis3_dev.odr_mask; - shift = ffs(lis3_dev.odr_mask) - 1; - return lis3_dev.odrs[(ctrl >> shift)]; + lis3->read(lis3, CTRL_REG1, &ctrl); + ctrl &= lis3->odr_mask; + shift = ffs(lis3->odr_mask) - 1; + return lis3->odrs[(ctrl >> shift)]; } -static int lis3lv02d_set_odr(int rate) +static int lis3lv02d_get_pwron_wait(struct lis3lv02d *lis3) +{ + int div = lis3lv02d_get_odr(lis3); + + if (WARN_ONCE(div == 0, "device returned spurious data")) + return -ENXIO; + + /* LIS3 power on delay is quite long */ + msleep(lis3->pwron_delay / div); + return 0; +} + +static int lis3lv02d_set_odr(struct lis3lv02d *lis3, int rate) { u8 ctrl; int i, len, shift; @@ -214,14 +226,14 @@ static int lis3lv02d_set_odr(int rate) if (!rate) return -EINVAL; - lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl); - ctrl &= ~lis3_dev.odr_mask; - len = 1 << hweight_long(lis3_dev.odr_mask); /* # of possible values */ - shift = ffs(lis3_dev.odr_mask) - 1; + lis3->read(lis3, CTRL_REG1, &ctrl); + ctrl &= ~lis3->odr_mask; + len = 1 << hweight_long(lis3->odr_mask); /* # of possible values */ + shift = ffs(lis3->odr_mask) - 1; for (i = 0; i < len; i++) - if (lis3_dev.odrs[i] == rate) { - lis3_dev.write(&lis3_dev, CTRL_REG1, + if (lis3->odrs[i] == rate) { + lis3->write(lis3, CTRL_REG1, ctrl | (i << shift)); return 0; } @@ -240,12 +252,12 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3]) mutex_lock(&lis3->mutex); irq_cfg = lis3->irq_cfg; - if (lis3_dev.whoami == WAI_8B) { + if (lis3->whoami == WAI_8B) { lis3->data_ready_count[IRQ_LINE0] = 0; lis3->data_ready_count[IRQ_LINE1] = 0; /* Change interrupt cfg to data ready for selftest */ - atomic_inc(&lis3_dev.wake_thread); + atomic_inc(&lis3->wake_thread); lis3->irq_cfg = LIS3_IRQ1_DATA_READY | LIS3_IRQ2_DATA_READY; lis3->read(lis3, CTRL_REG3, &ctrl_reg_data); lis3->write(lis3, CTRL_REG3, (ctrl_reg_data & @@ -253,12 +265,12 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3]) (LIS3_IRQ1_DATA_READY | LIS3_IRQ2_DATA_READY)); } - if (lis3_dev.whoami == WAI_3DC) { + if (lis3->whoami == WAI_3DC) { ctlreg = CTRL_REG4; selftest = CTRL4_ST0; } else { ctlreg = CTRL_REG1; - if (lis3_dev.whoami == WAI_12B) + if (lis3->whoami == WAI_12B) selftest = CTRL1_ST; else selftest = CTRL1_STP; @@ -266,7 +278,9 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3]) lis3->read(lis3, ctlreg, ®); lis3->write(lis3, ctlreg, (reg | selftest)); - msleep(lis3->pwron_delay / lis3lv02d_get_odr()); + ret = lis3lv02d_get_pwron_wait(lis3); + if (ret) + goto fail; /* Read directly to avoid axis remap */ x = lis3->read_data(lis3, OUTX); @@ -275,7 +289,9 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3]) /* back to normal settings */ lis3->write(lis3, ctlreg, reg); - msleep(lis3->pwron_delay / lis3lv02d_get_odr()); + ret = lis3lv02d_get_pwron_wait(lis3); + if (ret) + goto fail; results[0] = x - lis3->read_data(lis3, OUTX); results[1] = y - lis3->read_data(lis3, OUTY); @@ -283,9 +299,9 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3]) ret = 0; - if (lis3_dev.whoami == WAI_8B) { + if (lis3->whoami == WAI_8B) { /* Restore original interrupt configuration */ - atomic_dec(&lis3_dev.wake_thread); + atomic_dec(&lis3->wake_thread); lis3->write(lis3, CTRL_REG3, ctrl_reg_data); lis3->irq_cfg = irq_cfg; @@ -363,8 +379,9 @@ void lis3lv02d_poweroff(struct lis3lv02d *lis3) } EXPORT_SYMBOL_GPL(lis3lv02d_poweroff); -void lis3lv02d_poweron(struct lis3lv02d *lis3) +int lis3lv02d_poweron(struct lis3lv02d *lis3) { + int err; u8 reg; lis3->init(lis3); @@ -384,35 +401,41 @@ void lis3lv02d_poweron(struct lis3lv02d *lis3) lis3->write(lis3, CTRL_REG2, reg); } - /* LIS3 power on delay is quite long */ - msleep(lis3->pwron_delay / lis3lv02d_get_odr()); + err = lis3lv02d_get_pwron_wait(lis3); + if (err) + return err; if (lis3->reg_ctrl) lis3_context_restore(lis3); + + return 0; } EXPORT_SYMBOL_GPL(lis3lv02d_poweron); static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev) { + struct lis3lv02d *lis3 = pidev->private; int x, y, z; - mutex_lock(&lis3_dev.mutex); - lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); + mutex_lock(&lis3->mutex); + lis3lv02d_get_xyz(lis3, &x, &y, &z); input_report_abs(pidev->input, ABS_X, x); input_report_abs(pidev->input, ABS_Y, y); input_report_abs(pidev->input, ABS_Z, z); input_sync(pidev->input); - mutex_unlock(&lis3_dev.mutex); + mutex_unlock(&lis3->mutex); } static void lis3lv02d_joystick_open(struct input_polled_dev *pidev) { - if (lis3_dev.pm_dev) - pm_runtime_get_sync(lis3_dev.pm_dev); + struct lis3lv02d *lis3 = pidev->private; - if (lis3_dev.pdata && lis3_dev.whoami == WAI_8B && lis3_dev.idev) - atomic_set(&lis3_dev.wake_thread, 1); + if (lis3->pm_dev) + pm_runtime_get_sync(lis3->pm_dev); + + if (lis3->pdata && lis3->whoami == WAI_8B && lis3->idev) + atomic_set(&lis3->wake_thread, 1); /* * Update coordinates for the case where poll interval is 0 and * the chip in running purely under interrupt control @@ -422,14 +445,18 @@ static void lis3lv02d_joystick_open(struct input_polled_dev *pidev) static void lis3lv02d_joystick_close(struct input_polled_dev *pidev) { - atomic_set(&lis3_dev.wake_thread, 0); - if (lis3_dev.pm_dev) - pm_runtime_put(lis3_dev.pm_dev); + struct lis3lv02d *lis3 = pidev->private; + + atomic_set(&lis3->wake_thread, 0); + if (lis3->pm_dev) + pm_runtime_put(lis3->pm_dev); } -static irqreturn_t lis302dl_interrupt(int irq, void *dummy) +static irqreturn_t lis302dl_interrupt(int irq, void *data) { - if (!test_bit(0, &lis3_dev.misc_opened)) + struct lis3lv02d *lis3 = data; + + if (!test_bit(0, &lis3->misc_opened)) goto out; /* @@ -437,12 +464,12 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy) * the lid is closed. This leads to interrupts as soon as a little move * is done. */ - atomic_inc(&lis3_dev.count); + atomic_inc(&lis3->count); - wake_up_interruptible(&lis3_dev.misc_wait); - kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN); + wake_up_interruptible(&lis3->misc_wait); + kill_fasync(&lis3->async_queue, SIGIO, POLL_IN); out: - if (atomic_read(&lis3_dev.wake_thread)) + if (atomic_read(&lis3->wake_thread)) return IRQ_WAKE_THREAD; return IRQ_HANDLED; } @@ -514,28 +541,37 @@ static irqreturn_t lis302dl_interrupt_thread2_8b(int irq, void *data) static int lis3lv02d_misc_open(struct inode *inode, struct file *file) { - if (test_and_set_bit(0, &lis3_dev.misc_opened)) + struct lis3lv02d *lis3 = container_of(file->private_data, + struct lis3lv02d, miscdev); + + if (test_and_set_bit(0, &lis3->misc_opened)) return -EBUSY; /* already open */ - if (lis3_dev.pm_dev) - pm_runtime_get_sync(lis3_dev.pm_dev); + if (lis3->pm_dev) + pm_runtime_get_sync(lis3->pm_dev); - atomic_set(&lis3_dev.count, 0); + atomic_set(&lis3->count, 0); return 0; } static int lis3lv02d_misc_release(struct inode *inode, struct file *file) { - fasync_helper(-1, file, 0, &lis3_dev.async_queue); - clear_bit(0, &lis3_dev.misc_opened); /* release the device */ - if (lis3_dev.pm_dev) - pm_runtime_put(lis3_dev.pm_dev); + struct lis3lv02d *lis3 = container_of(file->private_data, + struct lis3lv02d, miscdev); + + fasync_helper(-1, file, 0, &lis3->async_queue); + clear_bit(0, &lis3->misc_opened); /* release the device */ + if (lis3->pm_dev) + pm_runtime_put(lis3->pm_dev); return 0; } static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { + struct lis3lv02d *lis3 = container_of(file->private_data, + struct lis3lv02d, miscdev); + DECLARE_WAITQUEUE(wait, current); u32 data; unsigned char byte_data; @@ -544,10 +580,10 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf, if (count < 1) return -EINVAL; - add_wait_queue(&lis3_dev.misc_wait, &wait); + add_wait_queue(&lis3->misc_wait, &wait); while (true) { set_current_state(TASK_INTERRUPTIBLE); - data = atomic_xchg(&lis3_dev.count, 0); + data = atomic_xchg(&lis3->count, 0); if (data) break; @@ -577,22 +613,28 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf, out: __set_current_state(TASK_RUNNING); - remove_wait_queue(&lis3_dev.misc_wait, &wait); + remove_wait_queue(&lis3->misc_wait, &wait); return retval; } static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait) { - poll_wait(file, &lis3_dev.misc_wait, wait); - if (atomic_read(&lis3_dev.count)) + struct lis3lv02d *lis3 = container_of(file->private_data, + struct lis3lv02d, miscdev); + + poll_wait(file, &lis3->misc_wait, wait); + if (atomic_read(&lis3->count)) return POLLIN | POLLRDNORM; return 0; } static int lis3lv02d_misc_fasync(int fd, struct file *file, int on) { - return fasync_helper(fd, file, on, &lis3_dev.async_queue); + struct lis3lv02d *lis3 = container_of(file->private_data, + struct lis3lv02d, miscdev); + + return fasync_helper(fd, file, on, &lis3->async_queue); } static const struct file_operations lis3lv02d_misc_fops = { @@ -605,85 +647,80 @@ static const struct file_operations lis3lv02d_misc_fops = { .fasync = lis3lv02d_misc_fasync, }; -static struct miscdevice lis3lv02d_misc_device = { - .minor = MISC_DYNAMIC_MINOR, - .name = "freefall", - .fops = &lis3lv02d_misc_fops, -}; - -int lis3lv02d_joystick_enable(void) +int lis3lv02d_joystick_enable(struct lis3lv02d *lis3) { struct input_dev *input_dev; int err; int max_val, fuzz, flat; int btns[] = {BTN_X, BTN_Y, BTN_Z}; - if (lis3_dev.idev) + if (lis3->idev) return -EINVAL; - lis3_dev.idev = input_allocate_polled_device(); - if (!lis3_dev.idev) + lis3->idev = input_allocate_polled_device(); + if (!lis3->idev) return -ENOMEM; - lis3_dev.idev->poll = lis3lv02d_joystick_poll; - lis3_dev.idev->open = lis3lv02d_joystick_open; - lis3_dev.idev->close = lis3lv02d_joystick_close; - lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL; - lis3_dev.idev->poll_interval_min = MDPS_POLL_MIN; - lis3_dev.idev->poll_interval_max = MDPS_POLL_MAX; - input_dev = lis3_dev.idev->input; + lis3->idev->poll = lis3lv02d_joystick_poll; + lis3->idev->open = lis3lv02d_joystick_open; + lis3->idev->close = lis3lv02d_joystick_close; + lis3->idev->poll_interval = MDPS_POLL_INTERVAL; + lis3->idev->poll_interval_min = MDPS_POLL_MIN; + lis3->idev->poll_interval_max = MDPS_POLL_MAX; + lis3->idev->private = lis3; + input_dev = lis3->idev->input; input_dev->name = "ST LIS3LV02DL Accelerometer"; input_dev->phys = DRIVER_NAME "/input0"; input_dev->id.bustype = BUS_HOST; input_dev->id.vendor = 0; - input_dev->dev.parent = &lis3_dev.pdev->dev; + input_dev->dev.parent = &lis3->pdev->dev; set_bit(EV_ABS, input_dev->evbit); - max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY; - if (lis3_dev.whoami == WAI_12B) { + max_val = (lis3->mdps_max_val * lis3->scale) / LIS3_ACCURACY; + if (lis3->whoami == WAI_12B) { fuzz = LIS3_DEFAULT_FUZZ_12B; flat = LIS3_DEFAULT_FLAT_12B; } else { fuzz = LIS3_DEFAULT_FUZZ_8B; flat = LIS3_DEFAULT_FLAT_8B; } - fuzz = (fuzz * lis3_dev.scale) / LIS3_ACCURACY; - flat = (flat * lis3_dev.scale) / LIS3_ACCURACY; + fuzz = (fuzz * lis3->scale) / LIS3_ACCURACY; + flat = (flat * lis3->scale) / LIS3_ACCURACY; input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat); input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat); input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat); - lis3_dev.mapped_btns[0] = lis3lv02d_get_axis(abs(lis3_dev.ac.x), btns); - lis3_dev.mapped_btns[1] = lis3lv02d_get_axis(abs(lis3_dev.ac.y), btns); - lis3_dev.mapped_btns[2] = lis3lv02d_get_axis(abs(lis3_dev.ac.z), btns); + lis3->mapped_btns[0] = lis3lv02d_get_axis(abs(lis3->ac.x), btns); + lis3->mapped_btns[1] = lis3lv02d_get_axis(abs(lis3->ac.y), btns); + lis3->mapped_btns[2] = lis3lv02d_get_axis(abs(lis3->ac.z), btns); - err = input_register_polled_device(lis3_dev.idev); + err = input_register_polled_device(lis3->idev); if (err) { - input_free_polled_device(lis3_dev.idev); - lis3_dev.idev = NULL; + input_free_polled_device(lis3->idev); + lis3->idev = NULL; } return err; } EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable); -void lis3lv02d_joystick_disable(void) +void lis3lv02d_joystick_disable(struct lis3lv02d *lis3) { - if (lis3_dev.irq) - free_irq(lis3_dev.irq, &lis3_dev); - if (lis3_dev.pdata && lis3_dev.pdata->irq2) - free_irq(lis3_dev.pdata->irq2, &lis3_dev); + if (lis3->irq) + free_irq(lis3->irq, lis3); + if (lis3->pdata && lis3->pdata->irq2) + free_irq(lis3->pdata->irq2, lis3); - if (!lis3_dev.idev) + if (!lis3->idev) return; - if (lis3_dev.irq) - misc_deregister(&lis3lv02d_misc_device); - input_unregister_polled_device(lis3_dev.idev); - input_free_polled_device(lis3_dev.idev); - lis3_dev.idev = NULL; + if (lis3->irq) + misc_deregister(&lis3->miscdev); + input_unregister_polled_device(lis3->idev); + input_free_polled_device(lis3->idev); + lis3->idev = NULL; } EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable); @@ -708,6 +745,7 @@ static void lis3lv02d_sysfs_poweron(struct lis3lv02d *lis3) static ssize_t lis3lv02d_selftest_show(struct device *dev, struct device_attribute *attr, char *buf) { + struct lis3lv02d *lis3 = dev_get_drvdata(dev); s16 values[3]; static const char ok[] = "OK"; @@ -715,8 +753,8 @@ static ssize_t lis3lv02d_selftest_show(struct device *dev, static const char irq[] = "FAIL_IRQ"; const char *res; - lis3lv02d_sysfs_poweron(&lis3_dev); - switch (lis3lv02d_selftest(&lis3_dev, values)) { + lis3lv02d_sysfs_poweron(lis3); + switch (lis3lv02d_selftest(lis3, values)) { case SELFTEST_FAIL: res = fail; break; @@ -735,33 +773,37 @@ static ssize_t lis3lv02d_selftest_show(struct device *dev, static ssize_t lis3lv02d_position_show(struct device *dev, struct device_attribute *attr, char *buf) { + struct lis3lv02d *lis3 = dev_get_drvdata(dev); int x, y, z; - lis3lv02d_sysfs_poweron(&lis3_dev); - mutex_lock(&lis3_dev.mutex); - lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); - mutex_unlock(&lis3_dev.mutex); + lis3lv02d_sysfs_poweron(lis3); + mutex_lock(&lis3->mutex); + lis3lv02d_get_xyz(lis3, &x, &y, &z); + mutex_unlock(&lis3->mutex); return sprintf(buf, "(%d,%d,%d)\n", x, y, z); } static ssize_t lis3lv02d_rate_show(struct device *dev, struct device_attribute *attr, char *buf) { - lis3lv02d_sysfs_poweron(&lis3_dev); - return sprintf(buf, "%d\n", lis3lv02d_get_odr()); + struct lis3lv02d *lis3 = dev_get_drvdata(dev); + + lis3lv02d_sysfs_poweron(lis3); + return sprintf(buf, "%d\n", lis3lv02d_get_odr(lis3)); } static ssize_t lis3lv02d_rate_set(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { + struct lis3lv02d *lis3 = dev_get_drvdata(dev); unsigned long rate; if (strict_strtoul(buf, 0, &rate)) return -EINVAL; - lis3lv02d_sysfs_poweron(&lis3_dev); - if (lis3lv02d_set_odr(rate)) + lis3lv02d_sysfs_poweron(lis3); + if (lis3lv02d_set_odr(lis3, rate)) return -EINVAL; return count; @@ -790,6 +832,7 @@ static int lis3lv02d_add_fs(struct lis3lv02d *lis3) if (IS_ERR(lis3->pdev)) return PTR_ERR(lis3->pdev); + platform_set_drvdata(lis3->pdev, lis3); return sysfs_create_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group); } @@ -803,7 +846,7 @@ int lis3lv02d_remove_fs(struct lis3lv02d *lis3) /* SYSFS may have left chip running. Turn off if necessary */ if (!pm_runtime_suspended(lis3->pm_dev)) - lis3lv02d_poweroff(&lis3_dev); + lis3lv02d_poweroff(lis3); pm_runtime_disable(lis3->pm_dev); pm_runtime_set_suspended(lis3->pm_dev); @@ -813,24 +856,24 @@ int lis3lv02d_remove_fs(struct lis3lv02d *lis3) } EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs); -static void lis3lv02d_8b_configure(struct lis3lv02d *dev, +static void lis3lv02d_8b_configure(struct lis3lv02d *lis3, struct lis3lv02d_platform_data *p) { int err; int ctrl2 = p->hipass_ctrl; if (p->click_flags) { - dev->write(dev, CLICK_CFG, p->click_flags); - dev->write(dev, CLICK_TIMELIMIT, p->click_time_limit); - dev->write(dev, CLICK_LATENCY, p->click_latency); - dev->write(dev, CLICK_WINDOW, p->click_window); - dev->write(dev, CLICK_THSZ, p->click_thresh_z & 0xf); - dev->write(dev, CLICK_THSY_X, + lis3->write(lis3, CLICK_CFG, p->click_flags); + lis3->write(lis3, CLICK_TIMELIMIT, p->click_time_limit); + lis3->write(lis3, CLICK_LATENCY, p->click_latency); + lis3->write(lis3, CLICK_WINDOW, p->click_window); + lis3->write(lis3, CLICK_THSZ, p->click_thresh_z & 0xf); + lis3->write(lis3, CLICK_THSY_X, (p->click_thresh_x & 0xf) | (p->click_thresh_y << 4)); - if (dev->idev) { - struct input_dev *input_dev = lis3_dev.idev->input; + if (lis3->idev) { + struct input_dev *input_dev = lis3->idev->input; input_set_capability(input_dev, EV_KEY, BTN_X); input_set_capability(input_dev, EV_KEY, BTN_Y); input_set_capability(input_dev, EV_KEY, BTN_Z); @@ -838,22 +881,22 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *dev, } if (p->wakeup_flags) { - dev->write(dev, FF_WU_CFG_1, p->wakeup_flags); - dev->write(dev, FF_WU_THS_1, p->wakeup_thresh & 0x7f); + lis3->write(lis3, FF_WU_CFG_1, p->wakeup_flags); + lis3->write(lis3, FF_WU_THS_1, p->wakeup_thresh & 0x7f); /* pdata value + 1 to keep this backward compatible*/ - dev->write(dev, FF_WU_DURATION_1, p->duration1 + 1); + lis3->write(lis3, FF_WU_DURATION_1, p->duration1 + 1); ctrl2 ^= HP_FF_WU1; /* Xor to keep compatible with old pdata*/ } if (p->wakeup_flags2) { - dev->write(dev, FF_WU_CFG_2, p->wakeup_flags2); - dev->write(dev, FF_WU_THS_2, p->wakeup_thresh2 & 0x7f); + lis3->write(lis3, FF_WU_CFG_2, p->wakeup_flags2); + lis3->write(lis3, FF_WU_THS_2, p->wakeup_thresh2 & 0x7f); /* pdata value + 1 to keep this backward compatible*/ - dev->write(dev, FF_WU_DURATION_2, p->duration2 + 1); + lis3->write(lis3, FF_WU_DURATION_2, p->duration2 + 1); ctrl2 ^= HP_FF_WU2; /* Xor to keep compatible with old pdata*/ } /* Configure hipass filters */ - dev->write(dev, CTRL_REG2, ctrl2); + lis3->write(lis3, CTRL_REG2, ctrl2); if (p->irq2) { err = request_threaded_irq(p->irq2, @@ -861,7 +904,7 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *dev, lis302dl_interrupt_thread2_8b, IRQF_TRIGGER_RISING | IRQF_ONESHOT | (p->irq_flags2 & IRQF_TRIGGER_MASK), - DRIVER_NAME, &lis3_dev); + DRIVER_NAME, lis3); if (err < 0) pr_err("No second IRQ. Limited functionality\n"); } @@ -871,93 +914,97 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *dev, * Initialise the accelerometer and the various subsystems. * Should be rather independent of the bus system. */ -int lis3lv02d_init_device(struct lis3lv02d *dev) +int lis3lv02d_init_device(struct lis3lv02d *lis3) { int err; irq_handler_t thread_fn; int irq_flags = 0; - dev->whoami = lis3lv02d_read_8(dev, WHO_AM_I); + lis3->whoami = lis3lv02d_read_8(lis3, WHO_AM_I); - switch (dev->whoami) { + switch (lis3->whoami) { case WAI_12B: pr_info("12 bits sensor found\n"); - dev->read_data = lis3lv02d_read_12; - dev->mdps_max_val = 2048; - dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B; - dev->odrs = lis3_12_rates; - dev->odr_mask = CTRL1_DF0 | CTRL1_DF1; - dev->scale = LIS3_SENSITIVITY_12B; - dev->regs = lis3_wai12_regs; - dev->regs_size = ARRAY_SIZE(lis3_wai12_regs); + lis3->read_data = lis3lv02d_read_12; + lis3->mdps_max_val = 2048; + lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_12B; + lis3->odrs = lis3_12_rates; + lis3->odr_mask = CTRL1_DF0 | CTRL1_DF1; + lis3->scale = LIS3_SENSITIVITY_12B; + lis3->regs = lis3_wai12_regs; + lis3->regs_size = ARRAY_SIZE(lis3_wai12_regs); break; case WAI_8B: pr_info("8 bits sensor found\n"); - dev->read_data = lis3lv02d_read_8; - dev->mdps_max_val = 128; - dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; - dev->odrs = lis3_8_rates; - dev->odr_mask = CTRL1_DR; - dev->scale = LIS3_SENSITIVITY_8B; - dev->regs = lis3_wai8_regs; - dev->regs_size = ARRAY_SIZE(lis3_wai8_regs); + lis3->read_data = lis3lv02d_read_8; + lis3->mdps_max_val = 128; + lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; + lis3->odrs = lis3_8_rates; + lis3->odr_mask = CTRL1_DR; + lis3->scale = LIS3_SENSITIVITY_8B; + lis3->regs = lis3_wai8_regs; + lis3->regs_size = ARRAY_SIZE(lis3_wai8_regs); break; case WAI_3DC: pr_info("8 bits 3DC sensor found\n"); - dev->read_data = lis3lv02d_read_8; - dev->mdps_max_val = 128; - dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; - dev->odrs = lis3_3dc_rates; - dev->odr_mask = CTRL1_ODR0|CTRL1_ODR1|CTRL1_ODR2|CTRL1_ODR3; - dev->scale = LIS3_SENSITIVITY_8B; + lis3->read_data = lis3lv02d_read_8; + lis3->mdps_max_val = 128; + lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; + lis3->odrs = lis3_3dc_rates; + lis3->odr_mask = CTRL1_ODR0|CTRL1_ODR1|CTRL1_ODR2|CTRL1_ODR3; + lis3->scale = LIS3_SENSITIVITY_8B; break; default: - pr_err("unknown sensor type 0x%X\n", dev->whoami); + pr_err("unknown sensor type 0x%X\n", lis3->whoami); return -EINVAL; } - dev->reg_cache = kzalloc(max(sizeof(lis3_wai8_regs), + lis3->reg_cache = kzalloc(max(sizeof(lis3_wai8_regs), sizeof(lis3_wai12_regs)), GFP_KERNEL); - if (dev->reg_cache == NULL) { + if (lis3->reg_cache == NULL) { printk(KERN_ERR DRIVER_NAME "out of memory\n"); return -ENOMEM; } - mutex_init(&dev->mutex); - atomic_set(&dev->wake_thread, 0); + mutex_init(&lis3->mutex); + atomic_set(&lis3->wake_thread, 0); - lis3lv02d_add_fs(dev); - lis3lv02d_poweron(dev); + lis3lv02d_add_fs(lis3); + err = lis3lv02d_poweron(lis3); + if (err) { + lis3lv02d_remove_fs(lis3); + return err; + } - if (dev->pm_dev) { - pm_runtime_set_active(dev->pm_dev); - pm_runtime_enable(dev->pm_dev); + if (lis3->pm_dev) { + pm_runtime_set_active(lis3->pm_dev); + pm_runtime_enable(lis3->pm_dev); } - if (lis3lv02d_joystick_enable()) + if (lis3lv02d_joystick_enable(lis3)) pr_err("joystick initialization failed\n"); /* passing in platform specific data is purely optional and only * used by the SPI transport layer at the moment */ - if (dev->pdata) { - struct lis3lv02d_platform_data *p = dev->pdata; + if (lis3->pdata) { + struct lis3lv02d_platform_data *p = lis3->pdata; - if (dev->whoami == WAI_8B) - lis3lv02d_8b_configure(dev, p); + if (lis3->whoami == WAI_8B) + lis3lv02d_8b_configure(lis3, p); irq_flags = p->irq_flags1 & IRQF_TRIGGER_MASK; - dev->irq_cfg = p->irq_cfg; + lis3->irq_cfg = p->irq_cfg; if (p->irq_cfg) - dev->write(dev, CTRL_REG3, p->irq_cfg); + lis3->write(lis3, CTRL_REG3, p->irq_cfg); if (p->default_rate) - lis3lv02d_set_odr(p->default_rate); + lis3lv02d_set_odr(lis3, p->default_rate); } /* bail if we did not get an IRQ from the bus layer */ - if (!dev->irq) { + if (!lis3->irq) { pr_debug("No IRQ. Disabling /dev/freefall\n"); goto out; } @@ -973,23 +1020,27 @@ int lis3lv02d_init_device(struct lis3lv02d *dev) * io-apic is not configurable (and generates a warning) but I keep it * in case of support for other hardware. */ - if (dev->pdata && dev->whoami == WAI_8B) + if (lis3->pdata && lis3->whoami == WAI_8B) thread_fn = lis302dl_interrupt_thread1_8b; else thread_fn = NULL; - err = request_threaded_irq(dev->irq, lis302dl_interrupt, + err = request_threaded_irq(lis3->irq, lis302dl_interrupt, thread_fn, IRQF_TRIGGER_RISING | IRQF_ONESHOT | irq_flags, - DRIVER_NAME, &lis3_dev); + DRIVER_NAME, lis3); if (err < 0) { pr_err("Cannot get IRQ\n"); goto out; } - if (misc_register(&lis3lv02d_misc_device)) + lis3->miscdev.minor = MISC_DYNAMIC_MINOR; + lis3->miscdev.name = "freefall"; + lis3->miscdev.fops = &lis3lv02d_misc_fops; + + if (misc_register(&lis3->miscdev)) pr_err("misc_register failed\n"); out: return 0; diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h index a1939589eb2c..2b1482ad3f16 100644 --- a/drivers/misc/lis3lv02d/lis3lv02d.h +++ b/drivers/misc/lis3lv02d/lis3lv02d.h @@ -21,6 +21,7 @@ #include <linux/platform_device.h> #include <linux/input-polldev.h> #include <linux/regulator/consumer.h> +#include <linux/miscdevice.h> /* * This driver tries to support the "digital" accelerometer chips from @@ -273,6 +274,8 @@ struct lis3lv02d { struct fasync_struct *async_queue; /* queue for the misc device */ wait_queue_head_t misc_wait; /* Wait queue for the misc device */ unsigned long misc_opened; /* bit0: whether the device is open */ + struct miscdevice miscdev; + int data_ready_count[2]; atomic_t wake_thread; unsigned char irq_cfg; @@ -282,10 +285,10 @@ struct lis3lv02d { }; int lis3lv02d_init_device(struct lis3lv02d *lis3); -int lis3lv02d_joystick_enable(void); -void lis3lv02d_joystick_disable(void); +int lis3lv02d_joystick_enable(struct lis3lv02d *lis3); +void lis3lv02d_joystick_disable(struct lis3lv02d *lis3); void lis3lv02d_poweroff(struct lis3lv02d *lis3); -void lis3lv02d_poweron(struct lis3lv02d *lis3); +int lis3lv02d_poweron(struct lis3lv02d *lis3); int lis3lv02d_remove_fs(struct lis3lv02d *lis3); extern struct lis3lv02d lis3_dev; diff --git a/drivers/misc/lis3lv02d/lis3lv02d_i2c.c b/drivers/misc/lis3lv02d/lis3lv02d_i2c.c index b20dfb4522d2..c02fea029dcf 100644 --- a/drivers/misc/lis3lv02d/lis3lv02d_i2c.c +++ b/drivers/misc/lis3lv02d/lis3lv02d_i2c.c @@ -79,8 +79,7 @@ static int lis3_i2c_init(struct lis3lv02d *lis3) u8 reg; int ret; - if (lis3->reg_ctrl) - lis3_reg_ctrl(lis3, LIS3_REG_ON); + lis3_reg_ctrl(lis3, LIS3_REG_ON); lis3->read(lis3, WHO_AM_I, ®); if (reg != lis3->whoami) @@ -106,10 +105,6 @@ static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client, struct lis3lv02d_platform_data *pdata = client->dev.platform_data; if (pdata) { - /* Regulator control is optional */ - if (pdata->driver_features & LIS3_USE_REGULATOR_CTRL) - lis3_dev.reg_ctrl = lis3_reg_ctrl; - if ((pdata->driver_features & LIS3_USE_BLOCK_READ) && (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))) @@ -131,15 +126,13 @@ static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client, goto fail; } - if (lis3_dev.reg_ctrl) { - lis3_dev.regulators[0].supply = reg_vdd; - lis3_dev.regulators[1].supply = reg_vdd_io; - ret = regulator_bulk_get(&client->dev, - ARRAY_SIZE(lis3_dev.regulators), - lis3_dev.regulators); - if (ret < 0) - goto fail; - } + lis3_dev.regulators[0].supply = reg_vdd; + lis3_dev.regulators[1].supply = reg_vdd_io; + ret = regulator_bulk_get(&client->dev, + ARRAY_SIZE(lis3_dev.regulators), + lis3_dev.regulators); + if (ret < 0) + goto fail; lis3_dev.pdata = pdata; lis3_dev.bus_priv = client; @@ -153,16 +146,19 @@ static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client, i2c_set_clientdata(client, &lis3_dev); /* Provide power over the init call */ - if (lis3_dev.reg_ctrl) - lis3_reg_ctrl(&lis3_dev, LIS3_REG_ON); + lis3_reg_ctrl(&lis3_dev, LIS3_REG_ON); ret = lis3lv02d_init_device(&lis3_dev); - if (lis3_dev.reg_ctrl) - lis3_reg_ctrl(&lis3_dev, LIS3_REG_OFF); + lis3_reg_ctrl(&lis3_dev, LIS3_REG_OFF); - if (ret == 0) - return 0; + if (ret) + goto fail2; + return 0; + +fail2: + regulator_bulk_free(ARRAY_SIZE(lis3_dev.regulators), + lis3_dev.regulators); fail: if (pdata && pdata->release_resources) pdata->release_resources(); @@ -177,12 +173,11 @@ static int __devexit lis3lv02d_i2c_remove(struct i2c_client *client) if (pdata && pdata->release_resources) pdata->release_resources(); - lis3lv02d_joystick_disable(); + lis3lv02d_joystick_disable(lis3); lis3lv02d_remove_fs(&lis3_dev); - if (lis3_dev.reg_ctrl) - regulator_bulk_free(ARRAY_SIZE(lis3->regulators), - lis3_dev.regulators); + regulator_bulk_free(ARRAY_SIZE(lis3->regulators), + lis3_dev.regulators); return 0; } diff --git a/drivers/misc/lis3lv02d/lis3lv02d_spi.c b/drivers/misc/lis3lv02d/lis3lv02d_spi.c index c1f8a8fbf694..b2c1be12d16f 100644 --- a/drivers/misc/lis3lv02d/lis3lv02d_spi.c +++ b/drivers/misc/lis3lv02d/lis3lv02d_spi.c @@ -83,7 +83,7 @@ static int __devinit lis302dl_spi_probe(struct spi_device *spi) static int __devexit lis302dl_spi_remove(struct spi_device *spi) { struct lis3lv02d *lis3 = spi_get_drvdata(spi); - lis3lv02d_joystick_disable(); + lis3lv02d_joystick_disable(lis3); lis3lv02d_poweroff(lis3); return lis3lv02d_remove_fs(&lis3_dev); |