Lines Matching full:ac

181 #define AC_READ(ac, reg)	((ac)->bops->read((ac)->dev, reg))  argument
182 #define AC_WRITE(ac, reg, val) ((ac)->bops->write((ac)->dev, reg, val)) argument
238 static void adxl34x_get_triple(struct adxl34x *ac, struct axis_triple *axis) in adxl34x_get_triple() argument
242 ac->bops->read_block(ac->dev, DATAX0, DATAZ1 - DATAX0 + 1, buf); in adxl34x_get_triple()
244 mutex_lock(&ac->mutex); in adxl34x_get_triple()
245 ac->saved.x = (s16) le16_to_cpu(buf[0]); in adxl34x_get_triple()
246 axis->x = ac->saved.x; in adxl34x_get_triple()
248 ac->saved.y = (s16) le16_to_cpu(buf[1]); in adxl34x_get_triple()
249 axis->y = ac->saved.y; in adxl34x_get_triple()
251 ac->saved.z = (s16) le16_to_cpu(buf[2]); in adxl34x_get_triple()
252 axis->z = ac->saved.z; in adxl34x_get_triple()
253 mutex_unlock(&ac->mutex); in adxl34x_get_triple()
256 static void adxl34x_service_ev_fifo(struct adxl34x *ac) in adxl34x_service_ev_fifo() argument
258 struct adxl34x_platform_data *pdata = &ac->pdata; in adxl34x_service_ev_fifo()
261 adxl34x_get_triple(ac, &axis); in adxl34x_service_ev_fifo()
263 input_event(ac->input, pdata->ev_type, pdata->ev_code_x, in adxl34x_service_ev_fifo()
264 axis.x - ac->swcal.x); in adxl34x_service_ev_fifo()
265 input_event(ac->input, pdata->ev_type, pdata->ev_code_y, in adxl34x_service_ev_fifo()
266 axis.y - ac->swcal.y); in adxl34x_service_ev_fifo()
267 input_event(ac->input, pdata->ev_type, pdata->ev_code_z, in adxl34x_service_ev_fifo()
268 axis.z - ac->swcal.z); in adxl34x_service_ev_fifo()
278 static void adxl34x_send_key_events(struct adxl34x *ac, in adxl34x_send_key_events() argument
285 input_report_key(ac->input, in adxl34x_send_key_events()
290 static void adxl34x_do_tap(struct adxl34x *ac, in adxl34x_do_tap() argument
293 adxl34x_send_key_events(ac, pdata, status, true); in adxl34x_do_tap()
294 input_sync(ac->input); in adxl34x_do_tap()
295 adxl34x_send_key_events(ac, pdata, status, false); in adxl34x_do_tap()
300 struct adxl34x *ac = handle; in adxl34x_irq() local
301 struct adxl34x_platform_data *pdata = &ac->pdata; in adxl34x_irq()
310 tap_stat = AC_READ(ac, ACT_TAP_STATUS); in adxl34x_irq()
314 int_stat = AC_READ(ac, INT_SOURCE); in adxl34x_irq()
317 adxl34x_report_key_single(ac->input, pdata->ev_code_ff); in adxl34x_irq()
320 dev_dbg(ac->dev, "OVERRUN\n"); in adxl34x_irq()
323 adxl34x_do_tap(ac, pdata, tap_stat); in adxl34x_irq()
326 adxl34x_do_tap(ac, pdata, tap_stat); in adxl34x_irq()
331 input_report_key(ac->input, in adxl34x_irq()
334 input_report_key(ac->input, in adxl34x_irq()
342 orient = AC_READ(ac, ORIENT); in adxl34x_irq()
348 if (ac->orient2d_saved != orient_code) { in adxl34x_irq()
349 ac->orient2d_saved = orient_code; in adxl34x_irq()
350 adxl34x_report_key_single(ac->input, in adxl34x_irq()
360 if (ac->orient3d_saved != orient_code) { in adxl34x_irq()
361 ac->orient3d_saved = orient_code; in adxl34x_irq()
362 adxl34x_report_key_single(ac->input, in adxl34x_irq()
371 samples = ENTRIES(AC_READ(ac, FIFO_STATUS)) + 1; in adxl34x_irq()
376 adxl34x_service_ev_fifo(ac); in adxl34x_irq()
391 if (ac->fifo_delay && (samples > 1)) in adxl34x_irq()
396 input_sync(ac->input); in adxl34x_irq()
401 static void __adxl34x_disable(struct adxl34x *ac) in __adxl34x_disable() argument
407 AC_WRITE(ac, POWER_CTL, 0); in __adxl34x_disable()
410 static void __adxl34x_enable(struct adxl34x *ac) in __adxl34x_enable() argument
412 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE); in __adxl34x_enable()
415 void adxl34x_suspend(struct adxl34x *ac) in adxl34x_suspend() argument
417 mutex_lock(&ac->mutex); in adxl34x_suspend()
419 if (!ac->suspended && !ac->disabled && ac->opened) in adxl34x_suspend()
420 __adxl34x_disable(ac); in adxl34x_suspend()
422 ac->suspended = true; in adxl34x_suspend()
424 mutex_unlock(&ac->mutex); in adxl34x_suspend()
428 void adxl34x_resume(struct adxl34x *ac) in adxl34x_resume() argument
430 mutex_lock(&ac->mutex); in adxl34x_resume()
432 if (ac->suspended && !ac->disabled && ac->opened) in adxl34x_resume()
433 __adxl34x_enable(ac); in adxl34x_resume()
435 ac->suspended = false; in adxl34x_resume()
437 mutex_unlock(&ac->mutex); in adxl34x_resume()
444 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_disable_show() local
446 return sprintf(buf, "%u\n", ac->disabled); in adxl34x_disable_show()
453 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_disable_store() local
461 mutex_lock(&ac->mutex); in adxl34x_disable_store()
463 if (!ac->suspended && ac->opened) { in adxl34x_disable_store()
465 if (!ac->disabled) in adxl34x_disable_store()
466 __adxl34x_disable(ac); in adxl34x_disable_store()
468 if (ac->disabled) in adxl34x_disable_store()
469 __adxl34x_enable(ac); in adxl34x_disable_store()
473 ac->disabled = !!val; in adxl34x_disable_store()
475 mutex_unlock(&ac->mutex); in adxl34x_disable_store()
485 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_calibrate_show() local
488 mutex_lock(&ac->mutex); in adxl34x_calibrate_show()
490 ac->hwcal.x * 4 + ac->swcal.x, in adxl34x_calibrate_show()
491 ac->hwcal.y * 4 + ac->swcal.y, in adxl34x_calibrate_show()
492 ac->hwcal.z * 4 + ac->swcal.z); in adxl34x_calibrate_show()
493 mutex_unlock(&ac->mutex); in adxl34x_calibrate_show()
502 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_calibrate_store() local
509 mutex_lock(&ac->mutex); in adxl34x_calibrate_store()
510 ac->hwcal.x -= (ac->saved.x / 4); in adxl34x_calibrate_store()
511 ac->swcal.x = ac->saved.x % 4; in adxl34x_calibrate_store()
513 ac->hwcal.y -= (ac->saved.y / 4); in adxl34x_calibrate_store()
514 ac->swcal.y = ac->saved.y % 4; in adxl34x_calibrate_store()
516 ac->hwcal.z -= (ac->saved.z / 4); in adxl34x_calibrate_store()
517 ac->swcal.z = ac->saved.z % 4; in adxl34x_calibrate_store()
519 AC_WRITE(ac, OFSX, (s8) ac->hwcal.x); in adxl34x_calibrate_store()
520 AC_WRITE(ac, OFSY, (s8) ac->hwcal.y); in adxl34x_calibrate_store()
521 AC_WRITE(ac, OFSZ, (s8) ac->hwcal.z); in adxl34x_calibrate_store()
522 mutex_unlock(&ac->mutex); in adxl34x_calibrate_store()
533 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_rate_show() local
535 return sprintf(buf, "%u\n", RATE(ac->pdata.data_rate)); in adxl34x_rate_show()
542 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_rate_store() local
550 mutex_lock(&ac->mutex); in adxl34x_rate_store()
552 ac->pdata.data_rate = RATE(val); in adxl34x_rate_store()
553 AC_WRITE(ac, BW_RATE, in adxl34x_rate_store()
554 ac->pdata.data_rate | in adxl34x_rate_store()
555 (ac->pdata.low_power_mode ? LOW_POWER : 0)); in adxl34x_rate_store()
557 mutex_unlock(&ac->mutex); in adxl34x_rate_store()
567 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_autosleep_show() local
570 ac->pdata.power_mode & (PCTL_AUTO_SLEEP | PCTL_LINK) ? 1 : 0); in adxl34x_autosleep_show()
577 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_autosleep_store() local
585 mutex_lock(&ac->mutex); in adxl34x_autosleep_store()
588 ac->pdata.power_mode |= (PCTL_AUTO_SLEEP | PCTL_LINK); in adxl34x_autosleep_store()
590 ac->pdata.power_mode &= ~(PCTL_AUTO_SLEEP | PCTL_LINK); in adxl34x_autosleep_store()
592 if (!ac->disabled && !ac->suspended && ac->opened) in adxl34x_autosleep_store()
593 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE); in adxl34x_autosleep_store()
595 mutex_unlock(&ac->mutex); in adxl34x_autosleep_store()
606 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_position_show() local
609 mutex_lock(&ac->mutex); in adxl34x_position_show()
611 ac->saved.x, ac->saved.y, ac->saved.z); in adxl34x_position_show()
612 mutex_unlock(&ac->mutex); in adxl34x_position_show()
624 struct adxl34x *ac = dev_get_drvdata(dev); in adxl34x_write_store() local
635 mutex_lock(&ac->mutex); in adxl34x_write_store()
636 AC_WRITE(ac, val >> 8, val & 0xFF); in adxl34x_write_store()
637 mutex_unlock(&ac->mutex); in adxl34x_write_store()
663 struct adxl34x *ac = input_get_drvdata(input); in adxl34x_input_open() local
665 mutex_lock(&ac->mutex); in adxl34x_input_open()
667 if (!ac->suspended && !ac->disabled) in adxl34x_input_open()
668 __adxl34x_enable(ac); in adxl34x_input_open()
670 ac->opened = true; in adxl34x_input_open()
672 mutex_unlock(&ac->mutex); in adxl34x_input_open()
679 struct adxl34x *ac = input_get_drvdata(input); in adxl34x_input_close() local
681 mutex_lock(&ac->mutex); in adxl34x_input_close()
683 if (!ac->suspended && !ac->disabled) in adxl34x_input_close()
684 __adxl34x_disable(ac); in adxl34x_input_close()
686 ac->opened = false; in adxl34x_input_close()
688 mutex_unlock(&ac->mutex); in adxl34x_input_close()
695 struct adxl34x *ac; in adxl34x_probe() local
707 ac = kzalloc(sizeof(*ac), GFP_KERNEL); in adxl34x_probe()
709 if (!ac || !input_dev) { in adxl34x_probe()
714 ac->fifo_delay = fifo_delay_default; in adxl34x_probe()
723 ac->pdata = *pdata; in adxl34x_probe()
724 pdata = &ac->pdata; in adxl34x_probe()
726 ac->input = input_dev; in adxl34x_probe()
727 ac->dev = dev; in adxl34x_probe()
728 ac->irq = irq; in adxl34x_probe()
729 ac->bops = bops; in adxl34x_probe()
731 mutex_init(&ac->mutex); in adxl34x_probe()
734 revid = AC_READ(ac, DEVID); in adxl34x_probe()
738 ac->model = 345; in adxl34x_probe()
741 ac->model = 346; in adxl34x_probe()
749 snprintf(ac->phys, sizeof(ac->phys), "%s/input0", dev_name(dev)); in adxl34x_probe()
751 input_dev->phys = ac->phys; in adxl34x_probe()
753 input_dev->id.product = ac->model; in adxl34x_probe()
758 input_set_drvdata(input_dev, ac); in adxl34x_probe()
760 __set_bit(ac->pdata.ev_type, input_dev->evbit); in adxl34x_probe()
762 if (ac->pdata.ev_type == EV_REL) { in adxl34x_probe()
788 ac->int_mask = FREE_FALL; in adxl34x_probe()
795 ac->int_mask |= ACTIVITY | INACTIVITY; in adxl34x_probe()
798 ac->int_mask |= WATERMARK; in adxl34x_probe()
800 ac->pdata.fifo_mode |= FIFO_STREAM; in adxl34x_probe()
802 ac->int_mask |= DATA_READY; in adxl34x_probe()
806 ac->int_mask |= SINGLE_TAP | DOUBLE_TAP; in adxl34x_probe()
809 ac->fifo_delay = false; in adxl34x_probe()
811 AC_WRITE(ac, POWER_CTL, 0); in adxl34x_probe()
813 err = request_threaded_irq(ac->irq, NULL, adxl34x_irq, in adxl34x_probe()
815 dev_name(dev), ac); in adxl34x_probe()
817 dev_err(dev, "irq %d busy?\n", ac->irq); in adxl34x_probe()
829 AC_WRITE(ac, OFSX, pdata->x_axis_offset); in adxl34x_probe()
830 ac->hwcal.x = pdata->x_axis_offset; in adxl34x_probe()
831 AC_WRITE(ac, OFSY, pdata->y_axis_offset); in adxl34x_probe()
832 ac->hwcal.y = pdata->y_axis_offset; in adxl34x_probe()
833 AC_WRITE(ac, OFSZ, pdata->z_axis_offset); in adxl34x_probe()
834 ac->hwcal.z = pdata->z_axis_offset; in adxl34x_probe()
835 AC_WRITE(ac, THRESH_TAP, pdata->tap_threshold); in adxl34x_probe()
836 AC_WRITE(ac, DUR, pdata->tap_duration); in adxl34x_probe()
837 AC_WRITE(ac, LATENT, pdata->tap_latency); in adxl34x_probe()
838 AC_WRITE(ac, WINDOW, pdata->tap_window); in adxl34x_probe()
839 AC_WRITE(ac, THRESH_ACT, pdata->activity_threshold); in adxl34x_probe()
840 AC_WRITE(ac, THRESH_INACT, pdata->inactivity_threshold); in adxl34x_probe()
841 AC_WRITE(ac, TIME_INACT, pdata->inactivity_time); in adxl34x_probe()
842 AC_WRITE(ac, THRESH_FF, pdata->free_fall_threshold); in adxl34x_probe()
843 AC_WRITE(ac, TIME_FF, pdata->free_fall_time); in adxl34x_probe()
844 AC_WRITE(ac, TAP_AXES, pdata->tap_axis_control); in adxl34x_probe()
845 AC_WRITE(ac, ACT_INACT_CTL, pdata->act_axis_control); in adxl34x_probe()
846 AC_WRITE(ac, BW_RATE, RATE(ac->pdata.data_rate) | in adxl34x_probe()
848 AC_WRITE(ac, DATA_FORMAT, pdata->data_range); in adxl34x_probe()
849 AC_WRITE(ac, FIFO_CTL, FIFO_MODE(pdata->fifo_mode) | in adxl34x_probe()
854 AC_WRITE(ac, INT_MAP, ac->int_mask | OVERRUN); in adxl34x_probe()
857 AC_WRITE(ac, INT_MAP, 0); in adxl34x_probe()
860 if (ac->model == 346 && ac->pdata.orientation_enable) { in adxl34x_probe()
861 AC_WRITE(ac, ORIENT_CONF, in adxl34x_probe()
862 ORIENT_DEADZONE(ac->pdata.deadzone_angle) | in adxl34x_probe()
863 ORIENT_DIVISOR(ac->pdata.divisor_length)); in adxl34x_probe()
865 ac->orient2d_saved = 1234; in adxl34x_probe()
866 ac->orient3d_saved = 1234; in adxl34x_probe()
878 ac->pdata.orientation_enable = 0; in adxl34x_probe()
881 AC_WRITE(ac, INT_ENABLE, ac->int_mask | OVERRUN); in adxl34x_probe()
883 ac->pdata.power_mode &= (PCTL_AUTO_SLEEP | PCTL_LINK); in adxl34x_probe()
885 return ac; in adxl34x_probe()
890 free_irq(ac->irq, ac); in adxl34x_probe()
893 kfree(ac); in adxl34x_probe()
899 int adxl34x_remove(struct adxl34x *ac) in adxl34x_remove() argument
901 sysfs_remove_group(&ac->dev->kobj, &adxl34x_attr_group); in adxl34x_remove()
902 free_irq(ac->irq, ac); in adxl34x_remove()
903 input_unregister_device(ac->input); in adxl34x_remove()
904 dev_dbg(ac->dev, "unregistered accelerometer\n"); in adxl34x_remove()
905 kfree(ac); in adxl34x_remove()