Lines Matching refs:ddev

177 	struct sdtx_device *ddev;  member
189 struct sdtx_device *ddev = container_of(kref, struct sdtx_device, kref); in __sdtx_device_release() local
191 mutex_destroy(&ddev->write_lock); in __sdtx_device_release()
192 kfree(ddev); in __sdtx_device_release()
195 static struct sdtx_device *sdtx_device_get(struct sdtx_device *ddev) in sdtx_device_get() argument
197 if (ddev) in sdtx_device_get()
198 kref_get(&ddev->kref); in sdtx_device_get()
200 return ddev; in sdtx_device_get()
203 static void sdtx_device_put(struct sdtx_device *ddev) in sdtx_device_put() argument
205 if (ddev) in sdtx_device_put()
206 kref_put(&ddev->kref, __sdtx_device_release); in sdtx_device_put()
212 static u16 sdtx_translate_base_state(struct sdtx_device *ddev, u8 state) in sdtx_translate_base_state() argument
225 dev_err(ddev->dev, "unknown base state: %#04x\n", state); in sdtx_translate_base_state()
230 static u16 sdtx_translate_latch_status(struct sdtx_device *ddev, u8 status) in sdtx_translate_latch_status() argument
249 dev_err(ddev->dev, "unknown latch status: %#04x\n", status); in sdtx_translate_latch_status()
254 static u16 sdtx_translate_cancel_reason(struct sdtx_device *ddev, u8 reason) in sdtx_translate_cancel_reason() argument
273 dev_err(ddev->dev, "unknown cancel reason: %#04x\n", reason); in sdtx_translate_cancel_reason()
281 static int sdtx_ioctl_get_base_info(struct sdtx_device *ddev, in sdtx_ioctl_get_base_info() argument
288 lockdep_assert_held_read(&ddev->lock); in sdtx_ioctl_get_base_info()
290 status = ssam_retry(ssam_bas_get_base, ddev->ctrl, &raw); in sdtx_ioctl_get_base_info()
294 info.state = sdtx_translate_base_state(ddev, raw.state); in sdtx_ioctl_get_base_info()
303 static int sdtx_ioctl_get_device_mode(struct sdtx_device *ddev, u16 __user *buf) in sdtx_ioctl_get_device_mode() argument
308 lockdep_assert_held_read(&ddev->lock); in sdtx_ioctl_get_device_mode()
310 status = ssam_retry(ssam_bas_get_device_mode, ddev->ctrl, &mode); in sdtx_ioctl_get_device_mode()
317 static int sdtx_ioctl_get_latch_status(struct sdtx_device *ddev, u16 __user *buf) in sdtx_ioctl_get_latch_status() argument
322 lockdep_assert_held_read(&ddev->lock); in sdtx_ioctl_get_latch_status()
324 status = ssam_retry(ssam_bas_get_latch_status, ddev->ctrl, &latch); in sdtx_ioctl_get_latch_status()
328 return put_user(sdtx_translate_latch_status(ddev, latch), buf); in sdtx_ioctl_get_latch_status()
333 struct sdtx_device *ddev = client->ddev; in __surface_dtx_ioctl() local
335 lockdep_assert_held_read(&ddev->lock); in __surface_dtx_ioctl()
347 return ssam_retry(ssam_bas_latch_lock, ddev->ctrl); in __surface_dtx_ioctl()
350 return ssam_retry(ssam_bas_latch_unlock, ddev->ctrl); in __surface_dtx_ioctl()
353 return ssam_retry(ssam_bas_latch_request, ddev->ctrl); in __surface_dtx_ioctl()
356 return ssam_retry(ssam_bas_latch_confirm, ddev->ctrl); in __surface_dtx_ioctl()
359 return ssam_retry(ssam_bas_latch_heartbeat, ddev->ctrl); in __surface_dtx_ioctl()
362 return ssam_retry(ssam_bas_latch_cancel, ddev->ctrl); in __surface_dtx_ioctl()
365 return sdtx_ioctl_get_base_info(ddev, (struct sdtx_base_info __user *)arg); in __surface_dtx_ioctl()
368 return sdtx_ioctl_get_device_mode(ddev, (u16 __user *)arg); in __surface_dtx_ioctl()
371 return sdtx_ioctl_get_latch_status(ddev, (u16 __user *)arg); in __surface_dtx_ioctl()
383 if (down_read_killable(&client->ddev->lock)) in surface_dtx_ioctl()
386 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &client->ddev->flags)) { in surface_dtx_ioctl()
387 up_read(&client->ddev->lock); in surface_dtx_ioctl()
393 up_read(&client->ddev->lock); in surface_dtx_ioctl()
402 struct sdtx_device *ddev = container_of(file->private_data, struct sdtx_device, mdev); in surface_dtx_open() local
410 client->ddev = sdtx_device_get(ddev); in surface_dtx_open()
420 down_write(&ddev->client_lock); in surface_dtx_open()
428 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &ddev->flags)) { in surface_dtx_open()
429 up_write(&ddev->client_lock); in surface_dtx_open()
431 sdtx_device_put(client->ddev); in surface_dtx_open()
436 list_add_tail(&client->node, &ddev->client_list); in surface_dtx_open()
437 up_write(&ddev->client_lock); in surface_dtx_open()
448 down_write(&client->ddev->client_lock); in surface_dtx_release()
450 up_write(&client->ddev->client_lock); in surface_dtx_release()
453 sdtx_device_put(client->ddev); in surface_dtx_release()
463 struct sdtx_device *ddev = client->ddev; in surface_dtx_read() local
467 if (down_read_killable(&ddev->lock)) in surface_dtx_read()
471 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &ddev->flags)) { in surface_dtx_read()
472 up_read(&ddev->lock); in surface_dtx_read()
479 up_read(&ddev->lock); in surface_dtx_read()
484 status = wait_event_interruptible(ddev->waitq, in surface_dtx_read()
487 &ddev->flags)); in surface_dtx_read()
491 if (down_read_killable(&ddev->lock)) in surface_dtx_read()
495 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &ddev->flags)) { in surface_dtx_read()
496 up_read(&ddev->lock); in surface_dtx_read()
503 up_read(&ddev->lock); in surface_dtx_read()
511 up_read(&ddev->lock); in surface_dtx_read()
517 up_read(&ddev->lock); in surface_dtx_read()
522 up_read(&ddev->lock); in surface_dtx_read()
531 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &client->ddev->flags)) in surface_dtx_poll()
534 poll_wait(file, &client->ddev->waitq, pt); in surface_dtx_poll()
594 static void sdtx_update_device_mode(struct sdtx_device *ddev, unsigned long delay);
597 static void sdtx_push_event(struct sdtx_device *ddev, struct sdtx_event *evt) in sdtx_push_event() argument
602 lockdep_assert_held(&ddev->write_lock); in sdtx_push_event()
604 down_read(&ddev->client_lock); in sdtx_push_event()
605 list_for_each_entry(client, &ddev->client_list, node) { in sdtx_push_event()
612 dev_warn(ddev->dev, "event buffer overrun\n"); in sdtx_push_event()
616 up_read(&ddev->client_lock); in sdtx_push_event()
618 wake_up_interruptible(&ddev->waitq); in sdtx_push_event()
623 struct sdtx_device *ddev = container_of(nf, struct sdtx_device, notif); in sdtx_notifier() local
650 dev_err(ddev->dev, in sdtx_notifier()
656 mutex_lock(&ddev->write_lock); in sdtx_notifier()
661 clear_bit(SDTX_DEVICE_DIRTY_BASE_BIT, &ddev->flags); in sdtx_notifier()
664 if (ddev->state.base.state == in->data[0] && in sdtx_notifier()
665 ddev->state.base.base_id == in->data[1]) in sdtx_notifier()
668 ddev->state.base.state = in->data[0]; in sdtx_notifier()
669 ddev->state.base.base_id = in->data[1]; in sdtx_notifier()
673 event.base.v.state = sdtx_translate_base_state(ddev, in->data[0]); in sdtx_notifier()
685 event.status.v = sdtx_translate_cancel_reason(ddev, in->data[0]); in sdtx_notifier()
689 clear_bit(SDTX_DEVICE_DIRTY_LATCH_BIT, &ddev->flags); in sdtx_notifier()
692 if (ddev->state.latch_status == in->data[0]) in sdtx_notifier()
695 ddev->state.latch_status = in->data[0]; in sdtx_notifier()
699 event.status.v = sdtx_translate_latch_status(ddev, in->data[0]); in sdtx_notifier()
703 sdtx_push_event(ddev, &event.common); in sdtx_notifier()
710 sdtx_update_device_mode(ddev, delay); in sdtx_notifier()
714 mutex_unlock(&ddev->write_lock); in sdtx_notifier()
731 struct sdtx_device *ddev = container_of(work, struct sdtx_device, mode_work.work); in sdtx_device_mode_workfn() local
738 status = ssam_retry(ssam_bas_get_device_mode, ddev->ctrl, &mode); in sdtx_device_mode_workfn()
740 dev_err(ddev->dev, "failed to get device mode: %d\n", status); in sdtx_device_mode_workfn()
745 status = ssam_retry(ssam_bas_get_base, ddev->ctrl, &base); in sdtx_device_mode_workfn()
747 dev_err(ddev->dev, "failed to get base info: %d\n", status); in sdtx_device_mode_workfn()
758 dev_dbg(ddev->dev, "device mode is invalid, trying again\n"); in sdtx_device_mode_workfn()
759 sdtx_update_device_mode(ddev, SDTX_DEVICE_MODE_DELAY_RECHECK); in sdtx_device_mode_workfn()
763 mutex_lock(&ddev->write_lock); in sdtx_device_mode_workfn()
764 clear_bit(SDTX_DEVICE_DIRTY_MODE_BIT, &ddev->flags); in sdtx_device_mode_workfn()
767 if (ddev->state.device_mode == mode) { in sdtx_device_mode_workfn()
768 mutex_unlock(&ddev->write_lock); in sdtx_device_mode_workfn()
772 ddev->state.device_mode = mode; in sdtx_device_mode_workfn()
778 sdtx_push_event(ddev, &event.e); in sdtx_device_mode_workfn()
782 input_report_switch(ddev->mode_switch, SW_TABLET_MODE, tablet); in sdtx_device_mode_workfn()
783 input_sync(ddev->mode_switch); in sdtx_device_mode_workfn()
785 mutex_unlock(&ddev->write_lock); in sdtx_device_mode_workfn()
788 static void sdtx_update_device_mode(struct sdtx_device *ddev, unsigned long delay) in sdtx_update_device_mode() argument
790 schedule_delayed_work(&ddev->mode_work, delay); in sdtx_update_device_mode()
794 static void __sdtx_device_state_update_base(struct sdtx_device *ddev, in __sdtx_device_state_update_base() argument
799 lockdep_assert_held(&ddev->write_lock); in __sdtx_device_state_update_base()
802 if (ddev->state.base.state == info.state && in __sdtx_device_state_update_base()
803 ddev->state.base.base_id == info.base_id) in __sdtx_device_state_update_base()
806 ddev->state.base = info; in __sdtx_device_state_update_base()
810 event.v.state = sdtx_translate_base_state(ddev, info.state); in __sdtx_device_state_update_base()
813 sdtx_push_event(ddev, &event.e); in __sdtx_device_state_update_base()
817 static void __sdtx_device_state_update_mode(struct sdtx_device *ddev, u8 mode) in __sdtx_device_state_update_mode() argument
828 lockdep_assert_held(&ddev->write_lock); in __sdtx_device_state_update_mode()
830 if (sdtx_device_mode_invalid(mode, ddev->state.base.state)) { in __sdtx_device_state_update_mode()
831 dev_dbg(ddev->dev, "device mode is invalid, trying again\n"); in __sdtx_device_state_update_mode()
832 sdtx_update_device_mode(ddev, SDTX_DEVICE_MODE_DELAY_RECHECK); in __sdtx_device_state_update_mode()
837 if (ddev->state.device_mode == mode) in __sdtx_device_state_update_mode()
840 ddev->state.device_mode = mode; in __sdtx_device_state_update_mode()
847 sdtx_push_event(ddev, &event.e); in __sdtx_device_state_update_mode()
851 input_report_switch(ddev->mode_switch, SW_TABLET_MODE, tablet); in __sdtx_device_state_update_mode()
852 input_sync(ddev->mode_switch); in __sdtx_device_state_update_mode()
856 static void __sdtx_device_state_update_latch(struct sdtx_device *ddev, u8 status) in __sdtx_device_state_update_latch() argument
860 lockdep_assert_held(&ddev->write_lock); in __sdtx_device_state_update_latch()
863 if (ddev->state.latch_status == status) in __sdtx_device_state_update_latch()
866 ddev->state.latch_status = status; in __sdtx_device_state_update_latch()
870 event.v = sdtx_translate_latch_status(ddev, status); in __sdtx_device_state_update_latch()
872 sdtx_push_event(ddev, &event.e); in __sdtx_device_state_update_latch()
877 struct sdtx_device *ddev = container_of(work, struct sdtx_device, state_work.work); in sdtx_device_state_workfn() local
883 set_bit(SDTX_DEVICE_DIRTY_BASE_BIT, &ddev->flags); in sdtx_device_state_workfn()
884 set_bit(SDTX_DEVICE_DIRTY_MODE_BIT, &ddev->flags); in sdtx_device_state_workfn()
885 set_bit(SDTX_DEVICE_DIRTY_LATCH_BIT, &ddev->flags); in sdtx_device_state_workfn()
895 status = ssam_retry(ssam_bas_get_base, ddev->ctrl, &base); in sdtx_device_state_workfn()
897 dev_err(ddev->dev, "failed to get base state: %d\n", status); in sdtx_device_state_workfn()
901 status = ssam_retry(ssam_bas_get_device_mode, ddev->ctrl, &mode); in sdtx_device_state_workfn()
903 dev_err(ddev->dev, "failed to get device mode: %d\n", status); in sdtx_device_state_workfn()
907 status = ssam_retry(ssam_bas_get_latch_status, ddev->ctrl, &latch); in sdtx_device_state_workfn()
909 dev_err(ddev->dev, "failed to get latch status: %d\n", status); in sdtx_device_state_workfn()
913 mutex_lock(&ddev->write_lock); in sdtx_device_state_workfn()
923 if (test_and_clear_bit(SDTX_DEVICE_DIRTY_BASE_BIT, &ddev->flags)) in sdtx_device_state_workfn()
924 __sdtx_device_state_update_base(ddev, base); in sdtx_device_state_workfn()
926 if (test_and_clear_bit(SDTX_DEVICE_DIRTY_MODE_BIT, &ddev->flags)) in sdtx_device_state_workfn()
927 __sdtx_device_state_update_mode(ddev, mode); in sdtx_device_state_workfn()
929 if (test_and_clear_bit(SDTX_DEVICE_DIRTY_LATCH_BIT, &ddev->flags)) in sdtx_device_state_workfn()
930 __sdtx_device_state_update_latch(ddev, latch); in sdtx_device_state_workfn()
932 mutex_unlock(&ddev->write_lock); in sdtx_device_state_workfn()
935 static void sdtx_update_device_state(struct sdtx_device *ddev, unsigned long delay) in sdtx_update_device_state() argument
937 schedule_delayed_work(&ddev->state_work, delay); in sdtx_update_device_state()
943 static int sdtx_device_init(struct sdtx_device *ddev, struct device *dev, in sdtx_device_init() argument
949 kref_init(&ddev->kref); in sdtx_device_init()
950 init_rwsem(&ddev->lock); in sdtx_device_init()
951 ddev->dev = dev; in sdtx_device_init()
952 ddev->ctrl = ctrl; in sdtx_device_init()
954 ddev->mdev.minor = MISC_DYNAMIC_MINOR; in sdtx_device_init()
955 ddev->mdev.name = "surface_dtx"; in sdtx_device_init()
956 ddev->mdev.nodename = "surface/dtx"; in sdtx_device_init()
957 ddev->mdev.fops = &surface_dtx_fops; in sdtx_device_init()
959 ddev->notif.base.priority = 1; in sdtx_device_init()
960 ddev->notif.base.fn = sdtx_notifier; in sdtx_device_init()
961 ddev->notif.event.reg = SSAM_EVENT_REGISTRY_SAM; in sdtx_device_init()
962 ddev->notif.event.id.target_category = SSAM_SSH_TC_BAS; in sdtx_device_init()
963 ddev->notif.event.id.instance = 0; in sdtx_device_init()
964 ddev->notif.event.mask = SSAM_EVENT_MASK_NONE; in sdtx_device_init()
965 ddev->notif.event.flags = SSAM_EVENT_SEQUENCED; in sdtx_device_init()
967 init_waitqueue_head(&ddev->waitq); in sdtx_device_init()
968 mutex_init(&ddev->write_lock); in sdtx_device_init()
969 init_rwsem(&ddev->client_lock); in sdtx_device_init()
970 INIT_LIST_HEAD(&ddev->client_list); in sdtx_device_init()
972 INIT_DELAYED_WORK(&ddev->mode_work, sdtx_device_mode_workfn); in sdtx_device_init()
973 INIT_DELAYED_WORK(&ddev->state_work, sdtx_device_state_workfn); in sdtx_device_init()
986 status = ssam_retry(ssam_bas_get_base, ddev->ctrl, &ddev->state.base); in sdtx_device_init()
990 status = ssam_retry(ssam_bas_get_device_mode, ddev->ctrl, &ddev->state.device_mode); in sdtx_device_init()
994 status = ssam_retry(ssam_bas_get_latch_status, ddev->ctrl, &ddev->state.latch_status); in sdtx_device_init()
999 ddev->mode_switch = input_allocate_device(); in sdtx_device_init()
1000 if (!ddev->mode_switch) in sdtx_device_init()
1003 ddev->mode_switch->name = "Microsoft Surface DTX Device Mode Switch"; in sdtx_device_init()
1004 ddev->mode_switch->phys = "ssam/01:11:01:00:00/input0"; in sdtx_device_init()
1005 ddev->mode_switch->id.bustype = BUS_HOST; in sdtx_device_init()
1006 ddev->mode_switch->dev.parent = ddev->dev; in sdtx_device_init()
1008 tablet_mode = (ddev->state.device_mode != SDTX_DEVICE_MODE_LAPTOP); in sdtx_device_init()
1009 input_set_capability(ddev->mode_switch, EV_SW, SW_TABLET_MODE); in sdtx_device_init()
1010 input_report_switch(ddev->mode_switch, SW_TABLET_MODE, tablet_mode); in sdtx_device_init()
1012 status = input_register_device(ddev->mode_switch); in sdtx_device_init()
1014 input_free_device(ddev->mode_switch); in sdtx_device_init()
1019 status = ssam_notifier_register(ddev->ctrl, &ddev->notif); in sdtx_device_init()
1024 status = misc_register(&ddev->mdev); in sdtx_device_init()
1032 sdtx_update_device_state(ddev, 0); in sdtx_device_init()
1036 ssam_notifier_unregister(ddev->ctrl, &ddev->notif); in sdtx_device_init()
1037 cancel_delayed_work_sync(&ddev->mode_work); in sdtx_device_init()
1039 input_unregister_device(ddev->mode_switch); in sdtx_device_init()
1045 struct sdtx_device *ddev; in sdtx_device_create() local
1048 ddev = kzalloc(sizeof(*ddev), GFP_KERNEL); in sdtx_device_create()
1049 if (!ddev) in sdtx_device_create()
1052 status = sdtx_device_init(ddev, dev, ctrl); in sdtx_device_create()
1054 sdtx_device_put(ddev); in sdtx_device_create()
1058 return ddev; in sdtx_device_create()
1061 static void sdtx_device_destroy(struct sdtx_device *ddev) in sdtx_device_destroy() argument
1069 set_bit(SDTX_DEVICE_SHUTDOWN_BIT, &ddev->flags); in sdtx_device_destroy()
1072 ssam_notifier_unregister(ddev->ctrl, &ddev->notif); in sdtx_device_destroy()
1075 cancel_delayed_work_sync(&ddev->mode_work); in sdtx_device_destroy()
1078 cancel_delayed_work_sync(&ddev->state_work); in sdtx_device_destroy()
1081 input_unregister_device(ddev->mode_switch); in sdtx_device_destroy()
1084 down_write(&ddev->client_lock); in sdtx_device_destroy()
1085 list_for_each_entry(client, &ddev->client_list, node) { in sdtx_device_destroy()
1088 up_write(&ddev->client_lock); in sdtx_device_destroy()
1091 wake_up_interruptible(&ddev->waitq); in sdtx_device_destroy()
1098 down_write(&ddev->lock); in sdtx_device_destroy()
1099 ddev->dev = NULL; in sdtx_device_destroy()
1100 ddev->ctrl = NULL; in sdtx_device_destroy()
1101 up_write(&ddev->lock); in sdtx_device_destroy()
1104 misc_deregister(&ddev->mdev); in sdtx_device_destroy()
1110 sdtx_device_put(ddev); in sdtx_device_destroy()
1120 struct sdtx_device *ddev = dev_get_drvdata(dev); in surface_dtx_pm_complete() local
1137 sdtx_update_device_state(ddev, msecs_to_jiffies(1000)); in surface_dtx_pm_complete()
1156 struct sdtx_device *ddev; in surface_dtx_platform_probe() local
1163 ddev = sdtx_device_create(&pdev->dev, ctrl); in surface_dtx_platform_probe()
1164 if (IS_ERR(ddev)) in surface_dtx_platform_probe()
1165 return PTR_ERR(ddev); in surface_dtx_platform_probe()
1167 platform_set_drvdata(pdev, ddev); in surface_dtx_platform_probe()
1201 struct sdtx_device *ddev; in surface_dtx_ssam_probe() local
1203 ddev = sdtx_device_create(&sdev->dev, sdev->ctrl); in surface_dtx_ssam_probe()
1204 if (IS_ERR(ddev)) in surface_dtx_ssam_probe()
1205 return PTR_ERR(ddev); in surface_dtx_ssam_probe()
1207 ssam_device_set_drvdata(sdev, ddev); in surface_dtx_ssam_probe()